我正在netbeans中创建一个项目。我已将其连接到我的数据库。我可以毫无问题地插入数据。更新单个约会时,每个id的约会将更改为用户输入的任何内容。请帮我。如果有错误或错误的条件,请检查我的代码。我认为我在适当的条件下遇到了问题。这是我的代码:
private void jsaveActionPerformed(java.awt.event.ActionEvent evt) {
String newname = jnewpat.getText();
String newage = jnage.getText();
String newgen = jngen.getText();
String renew = jnapp.getText();
if (newname.equals("") || newage.equals("") || newgen.equals("") || renew.equals(""))
{
JOptionPane.showMessageDialog(null,"Please complete all the fields!");
jnewpat.setText("");
jnage.setText("");
jngen.setText("");
jnapp.setText("");
}
else
{
String query = "UPDATE tblcare SET appointment = ? WHERE id = ?";
try {
try (PreparedStatement update = con.prepareStatement(query)) {
update.setString(1, jnapp.getText());
int id = 0;
update.setInt(2, id);
update.executeUpdate();
}
jnewpat.setText("");
jnage.setText("");
jngen.setText("");
jnapp.setText("");
Main back = new Main();
back.setVisible(true);
this.setVisible(false);
}
catch (HeadlessException | ClassNotFoundException | SQLException e) {
}
}
}