如何根据用户类型获得相应的阶段?

问题描述 投票:1回答:1

所以现在的问题是,我遇到了针对每种类型用户提示进入正确阶段的问题,我有一个方法可以检查他们的用户名并返回他们的角色类型,之后它会在验证他们的状态后将其提示到各自的阶段。用户和通行证。

我试图做一些调试,似乎方法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();
     }


    }
java sqlite javafx scenebuilder
1个回答
0
投票

我找到了一个解决方案,似乎我已经忘记执行查询,在将其添加到try块后,它似乎有工作。

rs.executeQuery();
© www.soinside.com 2019 - 2024. All rights reserved.