I have a java class where I am using an if condition. The code for the class is :
When I run this, the output that I get is
1 ADMIN 2nd loop - role derived from DB is: ADMIN
Thus, it looks like = 1 and = ADMIN, still the if condition fails.
To understand this better, I did a few tests.
When I used , the test passed.
When I used , the test passed again.
Hence, the only time this doesnt seem to work, is when role is given the value of rs.getString(2) (which is odd...because in the sysout statement , the output clearly shows that the value of rs.getString(2) is indeed ADMIN
Can anyone please help me understand what is going wrong here?
Thanks in advance for your time and patience.
The standard beginner error of using the == operator to compare the contents of two String objects. The == operator compares reference equality, i.e. it compares whether two references point at the same String. But it's possible for two different String objects to contain the same sequence of characters. If you want to test that (and you do want to test that), then use the equals() method: