I have a error in inserting data into myaql table from java.error says "java.lang.NullPointerException" with prepareStatement.below is my code.please help optimize me.
package studentCon;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import connection.connectionDB;
public class studentInsert {
public static void addproduct(String Last_name,String first_name,String email,String department,int salary) {
System.out.println(salary);
try{
Connection con=connectionDB.getConnection();
PreparedStatement stmt=con.prepareStatement("INSERT INTO `student`.`employees` (`last_name`, `first_name`, `email`, `department`, `salary`) VALUES (?, ?, ?,?,?)");
stmt.setString(1,Last_name);//1 specifies the first parameter in the query
stmt.setString(2,first_name);
stmt.setString(3, email);
stmt.setString(4, department);
stmt.setInt(5,salary);
int i=stmt.executeUpdate();
System.out.println(i+" records inserted");
con.close();
}catch(Exception e){ System.out.println(e);}
}
public static void main(String[] args){
// TODO Auto-generated method stub
addproduct("Htet","Mg","mghtet@gmail.com","IT",20000 );
}
}