0

I am trying to run a simple sql query but am getting a Null pointer exception. I tried to change everything possible but could not figure out the reason for this exception.

My part of code :

String sql = "Insert into CG (Date,Day,Pre,Sub) values (?,?,?,?)";
        try{
        pst = conn.prepareStatement(sql);
        pst.setString(1, "date");//4 value taken as input
        pst.setString(2, "day");
        pst.setString(3, "1");
        pst.setString(4, "0");
        pst.execute();
    }catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex);
    }

Edit : I am getting NPE at line pst = conn.prepareStatement(sql)

       My connection is :
Connection conn = DriverManager.getConnection("jdbc:sqlite:E:\\NetBeansProject\\At\\At.sqlite");

1 Answers1

0

Try this:

con.createStatement().executeUpdate(query);

CMPS
  • 7,733
  • 4
  • 28
  • 53
MeshBoy
  • 662
  • 5
  • 9