用户通过 8 个 JTextField 输入他的信息。此信息通过参数传递给 updateUser 方法,该方法使用此信息更新 SQL 表。这是我目前正在尝试做的事情,尽管当用户按下更新按钮时,数据库表没有任何更改
检索用户数据,创建 UserOperation 并调用 updateUser 方法
String userName = textFieldUserName.getText();
String userPassword = textField_1.getText();
String securityQuestion = textFieldSecQuestion.getText();
String securityAnswer = textFieldAnswer.getText();
String email = textFieldEmail.getText();
String fName = textFieldName.getText();
String phoneNumber = textFieldPhone.getText();
String department = textFieldDepartment.getText();
UserOperations userOperations = new UserOperations();
userOperations.updateUser(userName, userPassword, securityQuestion, securityAnswer, email, fName, phoneNumber, department);
updateUser 方法
public void updateUser (String userName, String userPassword, String securityQuestion, String securityAnswer, String email, String fName, String phoneNumber, String department)
{
try
{
String sql = "UPDATE systeuser SET username = ?,userpassword = ?,securityquestion = ?,securityanswer = ?,email = ?,fname = ?,phonenumber = ?,department = ? WHERE username = ?";
stmt = conn.prepareStatement(sql);
stmt.setString (1, userName);
stmt.setString (2, userPassword);
stmt.setString (3, securityQuestion);
stmt.setString (4, securityAnswer);
stmt.setString (5, email);
stmt.setString (6, fName);
stmt.setString (7, phoneNumber);
stmt.setString (8, department);
stmt.setString (9, userName);
stmt.executeUpdate( );
}
catch (Exception e)
{
e.printStackTrace ( );
}
}