I am trying to verify if the username and the password provided by the client. When I tried to execute my code, I got an error message:
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)
My code clientLogin() method:
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();
}
}
I think something is wrong with my sql query.