sql中could not extract ResultSet 问题~

ResultSet org.hibernate.exception.SQLGrammarException: could not extract ResultSet 这个问题..一般是自己的sql写的有问题。
在ide里边使用原生的sql时,要格外注意~下边说一个在springboot jpa中遇到的问题。
这个是正确的sql:

@Query(value = "select * from `tb_announcement_mgmt`"
  + " where `title`=:title and `is_del`=0 "
  + "and (case when :areaCode=0 then 1=1 else `area_code`=:areaCode end) limit 10", nativeQuery = true)

两个错误的sql:

case1:
@Query(value = "select * from `tb_announcement_mgmt`"
  + " where `title`=:title and `is_del`=0"
  + "and (case when :areaCode=0 then 1=1 else `area_code`=:areaCode end) limit 10", nativeQuery = true)

case2:
@Query(value = "select * from `tb_announcement_mgmt`"
  + " where `title`=:title and `is_del`=0 "
  + "and (case when :areaCode=0 then 1=1 "
  +"else `area_code`=:areaCode end) limit 10", nativeQuery = true)

emmmm…乍看起来是没有问题的~~但是.他就是有错的

第一个错误的地方在于:
” where title=:title and is_del=0”+ “and 在0和end之间 没有空格!! 。。。在执行sql的时候,ide将字符串拼成一个完整的sql,0和end之间没有空格,那么拼接的时候就会成为 where title=:title and is_del=0and (case 这样的格式,所以就报错了.
第二个错误的地方在于:
“and (case when :areaCode=0 then 1=1 “+”else area_code=:areaCode end) 这句中case else 是一个完整的语句,在一个括号中,是不能分开的..所以要写成
“and (case when :areaCode=0 then 1=1 else area_code=:areaCode end) 才是正确的。

~~有的问题就是要自己多注意了。

  • 9
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
引用\[1\]: could not extract ResultSet; SQL \[n/a\]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet 。 引用\[2\]:今天本地postman测试,出现这样错误:"msg": "could not extract ResultSet; SQL \[n/a\]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet", 。 引用\[3\]:访问API返回结果: { "status": 500, "error": "Internal Server Error", "message": "could not extract ResultSet; SQL \[n/a\]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet", } 解决方法: 。 问题: could not extract resultset 是什么意思?如何解决这个问题? 回答: "could not extract ResultSet"是一个错误信息,意味着无法提取结果集。这个错误通常与数据库查询有关,可能是由于SQL语法错误或数据库连接问题导致的。解决这个问题的方法包括检查SQL语句的正确性,确保数据库连接正常,以及查看相关的错误日志以获取更多详细信息。 #### 引用[.reference_title] - *1* [SQLGrammarException异常处理办法](https://blog.csdn.net/qq_43358385/article/details/113712604)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [could not extract ResultSet错误](https://blog.csdn.net/ZJUsunbin/article/details/79449825)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [请求数据库报错:“could not extract ResultSetSQL [n/a]; nested exception is org.hibernate....](https://blog.csdn.net/qq_41577750/article/details/125545241)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值