我有一个包含用户的数据库,每个用户都有一个角色。U 代表用户,A 代表管理员。我在名为 getRole() 的类中有一个方法,它获取用户广告的角色,将其作为字符串返回。在另一个类中,我调用此方法,将其结果保存到字符串,然后测试该字符串。如果是 A(管理员),则继续。问题是字符串返回 A,但程序没有继续。这里有什么问题?
getRole() 方法:
public String getRole() throws SQLException {
userid = "c##lambros";
password = "16111111";
jdbcUrl = "jdbc:oracle:thin:@localhost:1521:ORCL";
conn = DriverManager.getConnection(jdbcUrl, userid, password);
checkRole = "SELECT role FROM users where username = '" + usernameF.getText() + "' AND password = '" + passwordF.getText() + "' ";
System.out.println(checkRole);
stmt = conn.createStatement();
rset = stmt.executeQuery(checkRole);
while (rset.next()){
role = rset.getString(1);
System.out.println("The User's Role is " + role);
}
return role;
}
IF 声明:
Login login = new Login();
TermResultsFromDB terms = new TermResultsFromDB();
String role;
try {
role = login.getRole();
System.out.println(role);
if(role=="A"){
terms.getTerms(query);
terms.setVisible(true);
terms.setLocation(z, y);
terms.pack();
}
else if (role!="A")
System.out.println("Sorry! Not sufficient Privileges!");
} catch (SQLException f) {
}