不确定我在这里错过了什么,但似乎没有什么对我有帮助。我尝试了几种方法,但似乎都没有用。有什么想法吗?
这是我的密码:
btnUpdate = new JButton("Update");
btnUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String pid = textIDField.getText();
String fn = textFNameField.getText();
String ln = textLNameField.getText();
String add = addressField.getText();
String city = cityField.getText();
String phone = phoneField.getText();
String mid = medIDField.getText();
try{
Connection conn = DriverManager.getConnection("dbinfo");
String query = "UPDATE Patient SET PatID=?,FirstName=?,LastName=?,Address=?,City=?,Phone=?,MedID=? WHERE PatID=? AND MedID=?";
PreparedStatement pst = conn.prepareStatement(query);
pst.setString(1, pid);
pst.setString(2, fn );
pst.setString(3, ln );
pst.setString(4, add );
pst.setString(5, city );
pst.setString(6, phone );
pst.setString(7, mid );
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Patient Updated");
pst.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
});
发布于 2016-05-03 21:49:45
请您没有为最后两个参数设置值,所以请检查下面
try{
Connection conn = DriverManager.getConnection("dbinfo");
String query = "UPDATE Patient SET
PatID=?,FirstName=?,LastName=?,Address=?,City=?,Phone=?,MedID=? ` `WHERE PatID=? AND MedID=?";
PreparedStatement pst = conn.prepareStatement(query);
pst.setString(1, pid);
pst.setString(2, fn );
pst.setString(3, ln );
pst.setString(4, add );
pst.setString(5, city );
pst.setString(6, phone );
pst.setString(7, mid );
pst.setString(8, mid );//this last two
pst.setString(9, pid);
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Patient Updated");
pst.close();
}catch(Exception ex){
ex.printStackTrace();
}
https://stackoverflow.com/questions/37014817
复制相似问题