我创建了一个可以更改其密码的管理页面。到目前为止我的代码是:
@FXML
public void changePasswordButton(ActionEvent e) throws IOException, SQLException {
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mycredentials?autoReconnect=true&useSSL=false", username, password);
ps = connection.prepareStatement("SELECT pass FROM managerinfo WHERE pass = '"+oldpasswordBox.getText()+"'");
ps.setString(1, String.valueOf(oldpasswordBox.getText()));
ResultSet result = ps.executeQuery();
if(oldpasswordBox.getText().equals("")) {
oldpasswordLabel.setText("Please enter your old password.");
}
else {
if(result.next()) {
if (newPasswordBox.getText().equals("")) {
enterNewPassword.setText("Please enter your new password.");
}
else {
if(newPasswordBox.getText().equals(verifyNewPasswordBox.getText())) {
Statement s = (Statement) connection.createStatement();
String sql = "UPDATE managerinfo SET pass = '"+ newPasswordBox.getText()+"' WHERE user = 'admin'";
s.executeUpdate(sql);
passwordChanged.setText("Password Changed.");
}
else {
didNotMatched.setText("New password did not matched.");
}
}
}
else {
oldPasswordNotMached.setText("Old password did not matched.");
}
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
运行代码时,我的setText标签不起作用。我该怎么办?这是错误的逻辑吗?