M
M
mk112021-06-07 22:02:24
Java
mk11, 2021-06-07 22:02:24

Why do the lines from the database and from the form do not match?

There is this piece of code:

System.out.println("login :" + loginField.getText());
System.out.println("pass from fo:" +passwordField.getText());
DBHandler.openConnection();
ResultSet resultSet = DBHandler.executeUpdate("SELECT * FROM users WHERE login = '"+loginField.getText()+"'");

String passwordFromDB = null;
try {
   while (resultSet.next()) {
      passwordFromDB = resultSet.getString("password");
   }
} catch (SQLException throwables) {
  throwables.printStackTrace();
}
System.out.println("pass from DB :" + passwordFromDB);
if (passwordFromDB.toString() == passwordField.getText().toString()) {
    System.out.println(1);
}
DBHandler.closeConnection();

I pull out the login data from the database and try to compare the entered password with the password from the database, but they do not match, what did I mess up?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-06-07
@mk11

You are not comparing strings, but references to string objects.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question