Answer the question
In order to leave comments, you need to log in
How to compare a string received from a database with another string in Java?
//в queryResult хранится объект resultSet
queryResult.next();
// НЕОБХОДИМО: сравнить введенный пользователем login с логином в БД
if (login.equals(queryResult.getString("login"))){
System.out.println("ЛОГИН ПРАВИЛЬНЫЙ !");
if(password.equals(queryResult.getString("password"))){
System.out.println("ЛОГИН И ПАРОЛЬ ВЕРНЫ !");
return true;
}
else{
System.out.println("НЕВЕРНЫЙ ПАРОЛЬ !");
return false;
}
}
else{
System.out.println("НЕВЕРНЫЙ ЛОГИН");
return false;
}
Answer the question
In order to leave comments, you need to log in
Strings in Java are compared using equals(). Another thing is that the comparison returns false.
Exclude the following points:
- the entry in the database can be in uppercase or lowercase or camelCase, etc. Therefore, false is returned
- the source string or the string from the database may contain Cyrillic characters
- the encoding of the stored information in the database differs from utf8
if you can’t solve the issue, then drop the link to the git
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question