简体   繁体   English

尝试从数据库检索密码值时出错

[英]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.

相关问题 我正在尝试使用回收站视图从 Firebase 数据库中检索数据,但出现错误 - i am trying to retrieve the data from fire base database using recycler view but i am getting errors in it 尝试从其他类检索时的空值 - Null value when trying to retrieve from other class 格式错误的表达式:尝试从哈希图检索值时出现“错误” - Malformed expression :“Error” when trying to retrieve value from hashmap 我想从数据库中检索密码但是当程序运行结果为null时我不知道为什么? - i want to retrieve password from database but when program run result be null i don not know why? 从SQL数据库检索值 - Retrieve value from sql database 尝试检索字段值时出现NoSuchFieldException - NoSuchFieldException when trying to retrieve the value of field 尝试从SQL数据库检索数据到ListView Android时接收Null指针异常 - Recieveing Null Pointer Exception when trying to retrieve data from SQL database to listview android 尝试从数据库检索数据时出现 NoInitialContextException。 Heroku Java Web 应用程序 - NoInitialContextException when trying to retrieve data from database. Heroku Java web application 尝试从Firebase检索值,但获取空值? - Trying to retrieve value from Firebase, but getting null? 尝试从特定列检索值时,无法将java.lang.String转换为JSONObject - Get java.lang.String cannot be converted to JSONObject when trying to retrieve value from a specific column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM