Question: I have a table of representative in some schema in "mysql" and the table has a column named "userName". now for log in to program, i need to get data from text field in frame and check it with all usernames in in that column (username column has more than one row!) and if text of in username jtextfield equals with one of those rows, then the log in will be permitted !
i need a method to do that. i have write something but it does not work!
Here :

```
`public static boolean checkRep(String user, String pass) {
        String sql = "SELECT * FROM representative";
        Connection con = DBManager.getConnection();
        PreparedStatement st = null;
        try {
            st = con.prepareStatement(sql);
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()){
                if(user == rs.getString("passWord")){
                    System.out.println("Right");
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return true;
    }`

```

Answer: 
I think you should try this

```
....
   if (user.equals(rs.getString("passWord"))
....

```
The problem is with the string equality check in your if.Always check string equality using `equals` method. `==` operator checks if two reference variables point the same object. it checksif both the reference variables are identical. equals method checksif both objects are considered meaningfully equal.

```
if(user == rs.getString("passWord")){

should be

if(user.equals(rs.getString("passWord"))){

```