【解决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 的保留关键字一览

你可能感兴趣的:(bug解决,java)