I'm trying to check if my String key is in the NETFLIX column.
public boolean checkSerial(String key){
boolean isValid = false;
sql = "Select * from KEYS WHERE NETFLIX=?";
try{
ps = con.prepareStatement(sql);
ps.setString(1, key);
rs = ps.executeQuery();
if(rs.next())
isValid = true;
}catch(SQLException e){
System.out.println(e);
}
return isValid;
}
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'KEYS WHERE NETFLIX='IPMAN'' at line 1
KEYS
is a MySQL reserved keyword. So possibly you'll get an error even if there's nothing wrong with the query.
Either you've to avoid using MySQL reserved keywords, which can be found at
https://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
or
Use appropriate quotes for the keywords if you don't want to change your existing table. Like,
Select * from `KEYS` WHERE NETFLIX=?
Note: It's not a single quote, it's a symbol which is present along with the tilde symbol below the escape button (It's called backtick according to comment).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With