I am trying to add records to Sql Server in Java. In this function, program gives an error like that:
Connected
1
2
Error java.lang.NullPointerException
It is the output..
Function is below:
public class DB {
Connection con = null;
Statement stmt Nnull ;
component cmp = new Component();
public long pSave(Component cmp) {
String i = cmp.getI();
String s = cmp.getS();
String a = cmp.getA();
int t = cmp.getT();
int c = cmp.getC();
System.out.println("1");
try {
System.out.println("2");
stmt = con.createStatement();
System.out.println("3");
String SQL =
"INSERT INTO kisi (cl1,cl2,cl3,cl4,cl5) "
+ "VALUES(" + i + "," + s + "," + a + "," + c + "," + t + ")";
System.out.println("4");
stmt.executeUpdate(SQL);
System.out.println("Success");
return 1;
} catch(Exception e) {
System.out.println("Error " + e);
return 0;
}
}
}