Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.sql.SQLSyntaxErrorException。找不到错误_Java_Mysql - Fatal编程技术网

java.sql.SQLSyntaxErrorException。找不到错误

java.sql.SQLSyntaxErrorException。找不到错误,java,mysql,Java,Mysql,我现在得到了这个错误: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROMusersWHERElogin='Pac1man' ANDpassword='220v'' at line 1 我需要做什么来修

我现在得到了这个错误:

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROMusersWHERElogin='Pac1man' ANDpassword='220v'' at line 1
我需要做什么来修复它

我的问题是:

public void SignUpUser(User user){
        String insert = "INSERT INTO " + Const.USER_TABLE + "(" + Const.USER_NAME + ","
                + Const.USER_SECONDNAME + "," + Const.USER_LOGIN + "," + Const.USER_PASSWORD + ")"
                + "VALUES(?,?,?,?)";
        try {

            PreparedStatement prSt = getDbConnection().prepareStatement(insert);
            prSt.setString(1, user.getName());
            prSt.setString(2, user.getSecondName());
            prSt.setString(3, user.getUserName());
            prSt.setString(4, user.getPasswordName());

            prSt.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public ResultSet getUser(User user){
        ResultSet resSet = null;

        String select = "SELECT * FROM" + Const.USER_TABLE + "WHERE" +
                Const.USER_LOGIN + "=? AND" + Const.USER_PASSWORD + "=?";

        try {
            PreparedStatement prSt = getDbConnection().prepareStatement(select);
            prSt.setString(1, user.getUserName());
            prSt.setString(2, user.getPasswordName());

            resSet = prSt.executeQuery();
        }   catch (SQLException e) {
            e.printStackTrace();
        }   catch (ClassNotFoundException e){
            e.printStackTrace();
    }
    return resSet;
}}
有什么要点吗

您在
select
变量中有错误(缺少空格)。。 试试这个:

String select = "SELECT * FROM " + Const.USER_TABLE + " WHERE " +
                Const.USER_LOGIN + "=? AND " + Const.USER_PASSWORD + "=?";

您的查询无效,因为您没有添加空格

String select = "SELECT * FROM " + Const.USER_TABLE + " WHERE " +
                Const.USER_LOGIN + "=? AND " + Const.USER_PASSWORD + "=?";
现在使用上述代码,您的查询字符串将变为

 SELECT * FROM users WHERE login='Pac1man' AND password='220v'

我爱你:*谢谢兄弟