gpt4 book ai didi

java.sql.SQLSyntaxErrorException。找不到错误

转载 作者:行者123 更新时间:2023-11-29 10:01:02 27 4
gpt4 key购买 nike

我目前收到此错误:

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 + "=?";

关于java.sql.SQLSyntaxErrorException。找不到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52964523/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com