I have been making a simple a program to add a row in the data base using jdbc and spring in a maven project I have made the project watching videos as I am new to spring and database.
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mariam.employee;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;
/**
*
* @author shoaib kiani
*/
@Repository
public class EmployeeDaoImpl implements EmployeeDao{
NamedParameterJdbcTemplate namedPJT;
JdbcTemplate jt;
public SqlParameterSource getSqlP(Employee e)
{
MapSqlParameterSource m=new MapSqlParameterSource();
m.addValue("id", e.getID());
m.addValue("FirstName",e.getFirstName());
m.addValue("LastName",e.getLastName());
return m;}
@Override
public void save(Employee e) {
final String sql="INSERT INTO authors('FirstName','LastName') VALUE(?,? )";
namedPJT.update(sql , getSqlP(e));
System.out.println("Passed");
}
}
This is the exception:
Exception in thread "main" java.lang.NullPointerException
at com.mariam.employee.EmployeeDaoImpl.save(EmployeeDaoImpl.java:38)
at com.mariam.employee.Main.main(Main.java:22)