错误日志(.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的转义字符``即可

还是思维固化,想的不够灵活,没想过是字段名的问题
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值