简体   繁体   中英

MySQL Syntax error | You have an error in your SQL syntax;

Error:

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 'lock WHERE player='SrLolok'' at line 1

Code:

PreparedStatement search = instance.getConnection().prepareStatement("SELECT * FROM lock WHERE player=?;");
search.setString(1, player);
ResultSet rs = search.executeQuery();

lock is a reserved word in MySQL .

If you want to use it, you need to surround it with backticks:

SELECT * FROM `lock` WHERE player=?

Or better yet, use a table name that does not correspond to a reserved word, so you don't need to worry about this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM