lundi 21 septembre 2015

Having NullPointerException while inserting in sqlite database

getting NullPointerException. I wanted to insert data from two text fields to a table in sqlite database. But it's not working. Help me out.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
    try {

       String sql="Insert into survey_name(survey_name, no_of_ques) value (?,?)";
        pst=conn.prepareStatement(sql);

        pst.setString(1, survey_name.getText());
        pst.setString(2, questions.getText());

        pst.executeUpdate(sql);
        //pst.execute();
        JOptionPane.showMessageDialog(null, "Saved");

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }


}

Aucun commentaire:

Enregistrer un commentaire