javafx按钮更新代码没有错误,但数据库中的数据(值)没有更改

rqqzpn5f  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(214)

关闭。这个问题需要细节或清晰。它目前不接受答案。
**想改进这个问题吗?**通过编辑这个帖子来添加细节并澄清问题。

昨天关门了。
改进这个问题
代码中没有错误,但不会对我的数据库表进行任何更改。提前向助手表示非常感谢。表名是应用程序架构的联系人。它有以下列,名字,姓氏,号码,密码

Button updatebutton=new Button("Update");
        updatebutton.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {

                 try {

            String dbURL = "jdbc:derby://localhost:1527/CREATEACCOUNT"; 
                     Connection connection = DriverManager.getConnection(dbURL, "root","root"); 
                     System.out.println("connection created");
                      int num = Integer.parseInt(newcontactnumbertextfield.getText());
                         int pin = Integer.parseInt(newcontactpintextfield.getText());

      String myquery =  "update APP.CONTACTS set PIN=? where NUMBER=?";

                         PreparedStatement preparedStatement = connection.prepareStatement(myquery);

    preparedStatement.setInt(1, pin);
    preparedStatement.setInt(2, num);

    preparedStatement.executeUpdate();
    JOptionPane.showMessageDialog(null, "The pin is updated");
                        System.out.println("Statement executed");
                                                             }
catch (Exception e) {
    // Exception handling
  System.out.println("illigal");
                      JOptionPane.showMessageDialog(null, "The pin was not updated");
                          }
  }});

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题