### The error may involve defaultParameterMap ### The error occurred while setting parameters

本文记录了一个因表名与SQL关键字冲突导致的BadSqlGrammarException错误,并详细描述了解决过程,最终通过为表名添加反引号解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天遇到一个错误,运行RankDao.selectById(id)直接给我报错,很不理解

错误信息:

2021-09-22 10:40:58.824 ERROR 8364 --- [nio-8888-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is 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 'rank WHERE id=1' at line 1
### The error may exist in com/brilliantZC/music/dao/MusicRankDao.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT id,song_list_id,consumer_id,score FROM rank WHERE id=?
### 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 'rank WHERE id=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 'rank WHERE id=1' at line 1] with root cause

一开始各种百度了各种方法,有说

  1. 创建的表中列的值小于实际值而报错
  2. Controllor 层引入的 Service 接口上面忘记写 @Resource 或 @Autowired 注解
  3. Controllor 层调用的方法是 private 私有的,导致分发失败
  4. 检查Mapper接口代码是否符合规范(用的Mybatis-plus自动忽略)

都试过一遍还是不行,于是我拿着错误的sql语句执行

SELECT id,song_list_id,consumer_id,score FROM rank WHERE id=1

依然报错

music> SELECT id,song_list_id,consumer_id,score FROM rank WHERE id=1
[2021-09-22 10:55:58] [42000][1064] 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 'rank WHERE id=1' at line 1

然后我就迷茫了,接着我把查询语句去掉依然报错

SELECT id,song_list_id,consumer_id,score FROM rank

接着百度,看到因为rank是关键字,不能直接当做非关键字用,需要加上``来使用。换上后可执行了

SELECT id,song_list_id,consumer_id,score FROM `rank`

然后我就修改了表名,错误解决!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值