I am trying to insert the one column "array" in SQL. I create my database on SQL and I used Java to create the table but when I tried to insert the values in the array in the SQL, I have this error?
private class Handler_c implements ActionListener{
public void actionPerformed(ActionEvent arg0) {
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3307/database_vf","root","");
conn.setAutoCommit(false);
Statement stmt1 = null;
stmt1= conn.createStatement();
String query1 ="CREATE TABLE result (result INT)";
stmt1.execute(query1);
String query2 = "INSERT INTO result VALUES (?)";
PreparedStatement pst1 = null ;
for(int i=0; i<array.length; i++)
{ pst1.setDouble(i+1, array[i]);}
pst1 = (PreparedStatement) conn.prepareStatement(query2);
pst1.execute();
conn.commit();
pst1.close();
conn.close();
System.out.println("Success result to mysql table");
}
catch(ClassNotFoundException e){
System.out.println(e);
}catch(SQLException ex){
System.out.println(ex);
}
}
}
The error is :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at browse_gui$Handler_c.actionPerformed(browse_gui.java:191) ,,,,,,,,,,,,,,,,,,,,,,,,,,,,
This is line 191:
for(int i=0; i<array.length; i++)