check the manual that corresponds to your MySQL server version for the right syntax to use near 'and

使用mybatis时在mapper.xml文件动态sql运行时报:

Error querying database.  Cause: 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 'and id in ('help', 'f5ee267b-6' at line 4

mapper.xml 配置如下:

check the manual that corresponds to your MySQL server version for the right syntax to use near 'and

注意这种情况一般是语法问题,解决办法:

(1)语句给出哪里错误,如我的题目中给出“near”,说明在那附近有问题,我的错误是,在 id in ('help',前多加了and 导致语句有问题,去掉and就行了。

(2)还有一种情况是“表名”或者“表字段”使用了Mysql的关键字,需要改掉;在使用MySQL的时候,一般尽量避免用关键字作为表名,如使用关键字做表名,需要按标准写法给SQL语句加[](或是“)区分字段名和表名。