在android studio中使用JDBC登录级别

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

我正忙于创建一个连接到数据库以检查凭据的登录页面。现在我正在尝试创建一行代码,如果您是员工职位1,则转到Main2Activity,如果您是员工职位2,则转到Main3Activity。

这是我的代码:

String query = "select * from cc_employee where employee_username= '" + usernam.toString() + "' and employee_password = '"+ passwordd.toString() +"'  ";
                        Statement stmt = con.createStatement();
                        ResultSet rs = stmt.executeQuery(query);
                        if(rs.next())
                        {
                            z = "Login successful";
                            type = rs.getString("employee_position");
                            isSuccess=true;
                            con.close();
                            if (type = "1"){
                                Intent i=new Intent(login.this,Main2Activity.class);
                                startActivity(i);
                            }
                            else {
                                Intent i=new Intent(login.this,Main3Activity.class);
                                startActivity(i);
                            }

                        }
                        else
                        {
                            z = "Invalid Credentials!";
                            isSuccess = false;
                        }

这是我的databaseDatabase的图像

android sql sql-server jdbc
1个回答
0
投票

这是对我有用的答案

String query = "select * from cc_employee where employee_username= '" + usernam.toString() + "' and employee_password = '"+ passwordd.toString() +"'  ";                            
Statement stmt = con.createStatement();
                    ResultSet rs = stmt.executeQuery(query);
                    if(rs.next())
                    {
                        z = "Login successful";
                        type = rs.getInt("employee_position");
                        isSuccess=true;
                        con.close();

                        switch (type){
                            case 1:
                                intent = new Intent(login.this,Main2Activity.class);
                                break;
                            case 2:

                            intent = new Intent(login.this,Main3Activity.class);
                            break;

                            case 3:
                                intent = new Intent(login.this,Main4Activity.class);
                                break;
                            case 4:
                                intent = new Intent(login.this,Main5Activity.class);
                                break;
                        }
                        startActivity(intent);

                    }
                    else
                    {
                        z = "Invalid Credentials!";
                        isSuccess = false;
                    }
                }
© www.soinside.com 2019 - 2024. All rights reserved.