I have a database with users and each has a role. U for user and A for admin. I have a method in on class called getRole() which gets the role of a user ad returns it as String. In an other class I call this method, save its result to a String and then test that String. If it is A (admin) then proceed. The problem is that the String returns A, but the programm doesn't continue. What is wrong here?
getRole() Method:
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 Statement:
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) {
}