设为首页 加入收藏

TOP

sql中could not extract ResultSet 问题解决
2017-12-14 14:32:27 】 浏览:239
Tags: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) 才是正确的。

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

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇MongoDB 概念理解、MongoDB shell.. 下一篇SQLite的高级用法讲解

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目