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 (order_no, `uid`, addr_id,

记录专业实践过程中踩的坑

在订单表里添加记录的时候,显示报错如下:

1
2
3
4
5
6
7
8
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 (order_no, `uid`, addr_id, 
amount, `type`, freight,
`status`' 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 (order_no, `uid`, addr_id,
amount, `type`, freight,
`status`' at line 1v
...

经过排查,发现ordersql的保留字段(在排序的时候用到);

由于订单表的名字也为order,再加上mapper是由mybatis自动生成的,所以这个冲突需要手动解决一下。

OrderMapper.xml文件中,找到

1
2
3
4
5
insert into order (order_no, `uid`, addr_id, 
amount, `type`, freight,
`status`, payment_time, delivery_time,
finish_time, close_time, updated,
created)
将其中的order加上 `即可 即
1
2
3
4
5
insert into `order` (order_no, `uid`, addr_id, 
amount, `type`, freight,
`status`, payment_time, delivery_time,
finish_time, close_time, updated,
created)