[英]errors when trying to retrieve a password value from a database
First off, I understand there is probably a better way to access stored passwords. 首先,我了解可能有更好的方法来访问存储的密码。 This is a basic project trying to prove a basic concept. 这是一个基本项目,试图证明一个基本概念。
I am having problems trying to validate a users login with a database. 我在尝试验证用户使用数据库登录时遇到问题。
while(inputValue == null) {
System.out.println(PASSWORD_MESSAGE);
inputValue = in.nextLine();
try {
rs = statement.executeQuery(PASSWORD_QUERY);
while(rs.next()) {
System.out.println("TEST");
if(inputValue.equals(rs.getString("password"))) {
passwordValue = inputValue;
password= true;
break;
}
if(!inputValue.equals(rs.getString("password"))){
System.out.println(ERROR_MESSAGE);
inputValue = null;
break;
}
}
} catch(SQLException e) {
e.printStackTrace();
}
}
the value PASSWORD_QUERY
is ( SELECT password FROM project.account WHERE username='" + usernameValue + "'
) 值PASSWORD_QUERY
是( SELECT password FROM project.account WHERE username='" + usernameValue + "'
)
I have double checked this query in the database and it does work fine. 我已经在数据库中仔细检查了此查询,它的工作正常。 my error happens at the while loop. 我的错误发生在while循环中。 In debug mode it never enters the while loop and the system.out
message "TEST" never goes to the console. 在调试模式下,它永远不会进入while循环,并且system.out
消息“ TEST”永远不会进入控制台。
The error was actually in the query to the db. 错误实际上是在对数据库的查询中。 The variable the query was using was a static variable. 查询所使用的变量是静态变量。 I did not realize that the variables value for a constant would never change. 我没有意识到常量的变量值永远不会改变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.