【解决org.springframework.jdbc.BadSqlGrammarException】

出现报错:

Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6d0290d8] was not registered for synchronization because synchronization is not active
JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@22d477c2] will not be managed by Spring
==>  Preparing: select id, photo, name, group, comment, phone, organization, position, responsibilities, updatetime, isdelete, partID from supv_cadre WHERE isdelete='0' and name=?
==> Parameters: 李林(String)
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6d0290d8]

org.springframework.jdbc.BadSqlGrammarException: 
### 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 'group, comment, phone, organization, position, responsibilities, updatetime, isd' at line 1
### The error may exist in file [D:\Java\IDEA\supervision-system\target\classes\mapper\SupvCadreMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select id, photo, name, group, comment, phone, organization, position, responsibilities, updatetime, isdelete, partID     from supv_cadre      WHERE isdelete='0'                and name=?
### 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 'group, comment, phone, organization, position, responsibilities, updatetime, isd' 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 'group, comment, phone, organization, position, responsibilities, updatetime, isd' at line 1

这个异常表明在执行数据库查询时出现了SQL语法错误。错误信息提示说 SQL 语法中出现了问题,具体问题可能是由于 SQL 查询中的某个字段名与 SQL 的保留关键字冲突导致的。在SQL 查询中,有一个字段名叫做 group,这个名称与 SQL 的保留关键字 GROUP 冲突了,所以导致了 SQL 语法错误。

为了解决这个问题,可以采取以下步骤:

  • 更改字段名:最简单的方法是将字段名 group 更改为一个不会与 SQL 关键字冲突的名字,例如 group_name。这样, SQL 查询就不会引发语法错误。

同样容易产生冲突的字段还有“describe”。该字段虽然不是MySQL的保留字,但是被保留在了将来的 SQL Server 版本中。

SQL Server 的保留关键字一览

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值