错误日志(.BadSqlGrammarException:错误的sql参数异常,明明参数和表中数据都对应上了,其实很简单的错误,秒解决)...

nested exception is org.springframework.jdbc.BadSqlGrammarException

错误的sql参数异常,明明参数和表中数据都对应上了,其实很简单的错误,秒解决

{
    "timestamp": "2019-12-17T02:09:41.445+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "\r\n### 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\r\n### The error may involve com.czxy.mapper.StudentMapper.insertSelective-Inline\r\n### The error occurred while setting parameters\r\n### SQL: INSERT INTO tb_student  ( sname,gender,age,salary,desc,class_id ) VALUES( ?,?,?,?,?,? )\r\n### 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\n; 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的转义字符``即可

还是思维固化,想的不够灵活,没想过是字段名的问题

你可能感兴趣的:(错误日志,mysql,java,bug,sql,mybatis)