nested exception is org.springframework.jdbc.BadSqlGrammarException
错误的sql参数异常,明明参数和表中数据都对应上了,其实很简单的错误,秒解决
{
"timestamp": "2019-12-17T02:09:41.445+0000",
"status": 500,
"error": "Internal Server Error",
"message": "
### Error updating 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 "desc,class_id ) VALUES( "王权富贵",1,18,2000.0,"浩浩星河谁为主",1 )" at line 1
### The error may involve com.czxy.mapper.StudentMapper.insertSelective-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO tb_student ( sname,gender,age,salary,desc,class_id ) VALUES( ?,?,?,?,?,? )
### 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 "desc,class_id ) VALUES( "王权富贵",1,18,2000.0,"浩浩星河谁为主",1 )" 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 "desc,class_id ) VALUES( "王权富贵",1,18,2000.0,"浩浩星河谁为主",1 )" at line 1",
"path": "/student"
}
很简单的一个添加,报的的错是说我的sql语法有问题,检查了类里的信息,"desc,class_id"和表里的都对应上了,没问题,弄了好长时间,还是没弄出来,找班里的大神秒解决了,其实原因很简单"desc"是order里的降序排序(关键字),添加数据sql当然报语法错误
解决方案:
在@Column对应的表中数据上加上mysql的转义字符``即可