我正在尝试验证客户端提供的用户名和密码。 当我尝试执行代码时,出现错误消息:
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 '= 'enki' and password = 'enki$'' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
我的代码clientLogin()方法:
public static void clientLogin(String username, String password)
{
try
{
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/ikub", "root", "root");
PreparedStatement ps = connection.prepareStatement("select username, password from clieent"
+ "where username = ? and password = ?");
ps.setString(1, username);
ps.setString(2, password);
ResultSet rs = ps.executeQuery();
if (rs.next())
System.out.println("done");
else
System.out.println("error");
connection.close();
} catch (Exception e)
{
System.out.println("ERROR CANT LOGIN!");
System.out.println("_____________");
e.printStackTrace();
}
}
我认为我的SQL查询有问题。
答案 0 :(得分:1)
我的意思是...
“选择用户名和密码” +“其中用户名= .....”
或
“选择用户名和密码” +“其中用户名= .....”