如何根据用户类型获得各个阶段? [英] How to get the respective stage according to the user type?
问题描述
所以现在的问题是,我无法正确提示每种用户类型,我有一种方法可以检查用户名并返回其角色类型,然后将其提示到各自的阶段验证他们的用户并通过后.
So the problem right now is that I have issue with prompting towards the right stage for each type of users, I have a method which checks their username and return their type of role and after that it will prompt it to their respective stage after verifying their user and pass.
我已经尝试进行一些调试,并且似乎getUserRole方法存在问题,因为我无法在登录控制器中找到该方法.
I have tried to do some debug and it seems that the method getUserRole has something wrong with it, since I can't get into the method for it in the login controller.
**登录控制器*
@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();
}
}
推荐答案
我找到了一个解决方案,似乎我忘记了执行查询,将其添加到try块中后,似乎可以正常工作.>
I found a solution, it have seems that i have forgot to execute the query, after its added into the try block, it seems to have work.
rs.executeQuery();
这篇关于如何根据用户类型获得各个阶段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!