4

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

1
  • have you tried using ";" at the end? Commented Jun 1, 2015 at 6:18

1 Answer 1

9

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).

Sign up to request clarification or add additional context in comments.

1 Comment

That symbol is the backtick, or grave accent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.