所以现在的问题是,我无法针对每种类型的用户向正确的阶段进行提示,我有一种方法来检查其用户名并返回其角色类型,然后将其提示到各自的阶段验证他们的用户并通过后。
我已经尝试进行一些调试,并且似乎getUserRole方法存在问题,因为我无法在登录控制器中找到该方法。
**登录控制器*
@FXML
public void Login(ActionEvent event) {
try {
if (this.loginModel.isLogin(this.username.getText(), this.password.getText())) {
Stage stage = (Stage) this.login.getScene().getWindow();
stage.close();
if (this.loginModel.getUserRole(this.username.getText()) == 5) {
adminLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 4) {
technicianLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 3) {
custServiceLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 3) {
financeLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 3) {
managementLogin();
} else {
this.loginStatus.setText("The username or password entered is incorrect. Please check and try again.");
}
}
} catch (Exception localException) {
this.loginStatus.setText("The username or password entered is incorrect. Please check and try again.");
}
}
获取UserRole方法
public int getUserRole(String user) throws Exception
{
PreparedStatement pr = null;
ResultSet rs = null;
String sql = "SELECT * FROM Login WHERE username = ? AND role = ?";
try
{
pr = this.connection.prepareStatement(sql);
pr.setString(1, user);
if(rs.next())//cant initialized this if statement
{
int role = rs.getInt("role");
return role;
}
else{
return 0;
}
}
catch(SQLException ex)
{
return 0;
}
finally
{
pr.close();
rs.close();
}
}
答案 0 :(得分:0)
我找到了一个解决方案,似乎我忘记了执行查询,将其添加到try块中后,似乎可以正常工作。
rs.executeQuery();