数据库疑难杂症数据库疑难杂症 java.sql.SQLSyntaxErrorException: You have an error in
your SQL syntax; check the manual tha
数据库疑难杂症数据库疑难杂症 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 ‘order’ at line 1
数据库报错如下数据库报错如下:
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 ‘order’ at line 1
The error may exist in com/biyesheji/order/mapper/OrderMapper.java (best guess)
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: SELECT id,sale_money,cost_money,create_time,update_time,customer_id,contract_id FROM order
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 ‘order’ at line 1
; bad SQL grammar []; nested exception is 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 ‘order’ at line 1] with root cause
然后我复制控制台显示的自动生成的然后我复制控制台显示的自动生成的sql语句到数据库中运行,果不其然,也报同样的错语句到数据库中运行,果不其然,也报同样的错
SQL语句:SELECT id,sale_money,cost_money,create_time,update_time,customer_id,contract_id FROM order
下图为数据库报的错误
然后我检查SQL语句,发现生成的表名是order而并不是’order’,少了’’符号
正确的SQL语句应该是SELECT id,sale_money,cost_money,create_time,update_time,customer_id,contract_id FROM ‘order’
这说明这说明mybatis plus没有自动帮其添加没有自动帮其添加’’号,导致其无法识别对应的号,导致其无法识别对应的order表表
注意:注意:’ ‘号并不是单引号,是上侧数字键最左边的号并不是单引号,是上侧数字键最左边的~键的英文输入,既键的英文输入,既 ` 号号
解决方法:解决方法:
在在Order对应的对应的POJO类上添加类上添加@TableName注解,内容为加上了注解,内容为加上了’ ‘号的表名号的表名——等于我们帮等于我们帮mybatis plus加上加上’’号,这样就能读到号,这样就能读到order表啦表啦
作者:weixin_39716548
评论0