org.hibernate.exception.SQLGrammarException: could not execute query
来源:互联网 发布:怎么修改单机游戏数据 编辑:程序博客网 时间:2024/06/05 10:16
SQLGrammarException
org.hibernate.exception.SQLGrammarException: could not execute query
在项目的开发过程中,因为都是在基于SSH的环境下进行的项目开发,所在很多人习惯于使用Hibernate的HQL进行项目的开发,以提高项目开发的效率,但是在某些情况下,HQL是不能满足于项目的需求的,所以我们又不得不编写原生的SQL,对于有些人在习惯了hibernate带来的便利了,所以突然需要编写原生SQL时,可能会出现SQL书写语法错误的情况,以下为我的一个疏忽,关于这个问题,我想把它分享出来,希望能帮到你。
在往下看,Caused by: java.sql.SQLException: ORA-00936: 缺失表达式 ,如下图:
很明显告诉我们,SQL语法错误,或者关键字书写错误等,导致的查询无法执行,以下是我的一个示例SQL ,所要描述的问题都是一样的:
SQLQuery query = super.getSession().createSQLQuery(" SELECT * FROM (SELECT * FROM TLQ_CAR_OUT O, PARK_INFO G WHERE G.CODE = O.REGION ORDER BY O.OUTTIME DESC) N LEFT JOIN MONEY_CAR_RECORD R ON N.INTIME = R.IN_TIMEAND G.ORG_CODE LIKE ? || '%' ");
query.setString(0, getSessionUser());
List list = query.list();
如上面这个问题,注意细节 'AND G.ORG_CODE LIKE ? || '%' ' ,使用G调用ORG_CODE,是肯定调不到的,这句查询筛选条件写错地方了,这儿只给出了SQL的一个小片段,当时SQL太复杂了,眼睛都看花了,最后经过仔细排查,才发现的,正确的SQL如下:
SELECT * FROM (SELECT * FROM TLQ_CAR_OUT O, PARK_INFO G WHERE G.CODE = O.REGIONAND G.ORG_CODE LIKE ? || '%' ORDER BY O.OUTTIME DESC) N LEFT JOIN MONEY_CAR_RECORD R ON N.INTIME = R.IN_TIME
好了关于 " org.hibernate.exception.SQLGrammarException: could not execute query "一个原生SQL语法错误的问题,就解决了,在项目开发的过程中一定要注意细节问题,往往一些很难找到的问题就是出现在细节上。
歇后语:“共同学习,共同进步”,也希望大家多多关注CSND的IT社区。
- org.hibernate.exception.SQLGrammarException: could not execute query
- org.hibernate.exception.SQLGrammarException: could not execute query
- org.hibernate.exception.SQLGrammarException: could not execute query
- org.hibernate.exception.SQLGrammarException: could not execute query
- org.hibernate.exception.SQLGrammarException: could not execute query处理方式
- org.hibernate.exception.SQLGrammarException: could not execute query
- org.hibernate.exception.SQLGrammarException: could not execute query
- org.hibernate.exception.SQLGrammarException: could not execute query处理方式
- 【J2EE】org.hibernate.exception.SQLGrammarException: could not execute query错误
- org.hibernate.exception.SQLGrammarException: could not execute query处理方式
- org.hibernate.exception.SQLGrammarException: could not execute query
- nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
- org.hibernate.exception.SQLGrammarException: could not execute query错误解决笔记
- hibernate出现异常org.hibernate.exception.SQLGrammarException:could not execute
- org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
- org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
- 错误:org.hibernate.exception.SQLGrammarException: could not execute
- org.hibernate.exception.SQLGrammarException: could not execute statement错误
- Dubbo
- 关于application/json返回问题
- python之实战----决策树(ID3,C4.5,CART)战sin(x)+随机噪声
- Fiddler—Fiddler打断点(bpu)
- 重读avro文件 对文件进行简单的mr计算
- org.hibernate.exception.SQLGrammarException: could not execute query
- php设计模式-简单工厂模式
- mysql数据库报错了怎么办(got error 28 from storage engine)
- 清华x-lab AI研习社 | 创新工场王咏刚:人工智能在线下落地难不是问题_而是巨大的机遇
- 从输入URL到页面渲染完成
- 微信h5牛牛源码搭建教程
- 淘宝开源Key/Value结构数据存储系统Tair技术剖析
- Getting started with TensorFlow
- 关于Spring几个特殊类的说明与备忘(BeanNameAware\ApplicationContextAware\InitializingBean\DisposableBean)