0

It runs but the time i press the button to save the records i want to save it doesn’t seem to work

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        
        try {
 String sql = "insert into BOOK_FILE (title,author,description,price) "
 + " values (?,?,?,?)";
 PreparedStatement pst = conn.prepareStatement(sql);
 pst.setString(1, jTextField5.getText());
 pst.setString(2, jTextField6.getText());
 pst.setString(3, jTextField7.getText());
 pst.setString(4, jTextField8.getText());
 pst.execute();
 
 JOptionPane.showMessageDialog(null, "Save success!");
 conn.close();
 System.exit(0);
 } catch (SQLException e) {
 JOptionPane.showMessageDialog(null, "Save failed!");
 e.printStackTrace(System.err);
 } 
 
    }  

im thinking that the problem is here or it might be here

private void initConnection() {
        
 try {
 conn = DriverManager.getConnection("jdbc:derby://localhost:1527/sample");

 } catch (SQLException e) {
 e.printStackTrace(System.err);
 }
 
} 


                                 
Anonymous Asked question May 14, 2021