org.hibernate.exception.SQLGrammarException: could not execute query

Hibernate JIRA | kalyan buddala | 7 years ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    I need to create a dynamic query based on the some condition. I don't want to hardcode this query in my java class. So that's the reason i want to get this using Named query in hibernate. Below is how iam trying to implement. DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String today = sdf.format(date); Query query = session.getNamedQuery("findDateDifference"); query.setString(1, today); List date_Diff_List = query.list(); <sql-query name="findDateDifference"><![CDATA[ select (? - temp.bv_date) as days from ( select CLO_DTE as bv_date from BRAND ) temp]]> </sql-query> I need to pass the value to the '?' which is given in above query. When I run the above code it gives me error as below. Can anyone please give me some suggestions how to fix this issue. Hibernate: select (? - temp.bv_date) as days from ( select CLO_DTE as bv_date from BRAND ) temp org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:1502) at org.hibernate.loader.Loader.list(Loader.java:1482) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1333) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:146) at com.hibernate.ExceptionTest.getDateDifference(ExceptionTest.java:219) at com.hibernate.ExceptionTest.main(ExceptionTest.java:43) Caused by: com.ibm.db2.jcc.a.SqlException: DB2 SQL error: SQLCODE: -171, SQLSTATE: 42815, SQLERRMC: 2;- at com.ibm.db2.jcc.a.hd.e(hd.java:1659) at com.ibm.db2.jcc.a.hd.a(hd.java:1235) at com.ibm.db2.jcc.a.hd.a(hd.java:1221) at com.ibm.db2.jcc.c.jb.h(jb.java:142) at com.ibm.db2.jcc.c.jb.a(jb.java:43) at com.ibm.db2.jcc.c.w.a(w.java:30) at com.ibm.db2.jcc.c.cc.g(cc.java:160) at com.ibm.db2.jcc.a.hd.n(hd.java:1215) at com.ibm.db2.jcc.a.id.gb(id.java:1780) at com.ibm.db2.jcc.a.id.d(id.java:2255) at com.ibm.db2.jcc.a.id.X(id.java:505) at com.ibm.db2.jcc.a.id.executeQuery(id.java:488) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:107) at org.hibernate.loader.Loader.getResultSet(Loader.java:1183) at org.hibernate.loader.Loader.doQuery(Loader.java:363) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203) at org.hibernate.loader.Loader.doList(Loader.java:1499) ... 6 more

    Hibernate JIRA | 7 years ago | kalyan buddala
    org.hibernate.exception.SQLGrammarException: could not execute query
  2. 0

    I need to create a dynamic query based on the some condition. I don't want to hardcode this query in my java class. So that's the reason i want to get this using Named query in hibernate. Below is how iam trying to implement. DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String today = sdf.format(date); Query query = session.getNamedQuery("findDateDifference"); query.setString(1, today); List date_Diff_List = query.list(); <sql-query name="findDateDifference"><![CDATA[ select (? - temp.bv_date) as days from ( select CLO_DTE as bv_date from BRAND ) temp]]> </sql-query> I need to pass the value to the '?' which is given in above query. When I run the above code it gives me error as below. Can anyone please give me some suggestions how to fix this issue. Hibernate: select (? - temp.bv_date) as days from ( select CLO_DTE as bv_date from BRAND ) temp org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:1502) at org.hibernate.loader.Loader.list(Loader.java:1482) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1333) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:146) at com.hibernate.ExceptionTest.getDateDifference(ExceptionTest.java:219) at com.hibernate.ExceptionTest.main(ExceptionTest.java:43) Caused by: com.ibm.db2.jcc.a.SqlException: DB2 SQL error: SQLCODE: -171, SQLSTATE: 42815, SQLERRMC: 2;- at com.ibm.db2.jcc.a.hd.e(hd.java:1659) at com.ibm.db2.jcc.a.hd.a(hd.java:1235) at com.ibm.db2.jcc.a.hd.a(hd.java:1221) at com.ibm.db2.jcc.c.jb.h(jb.java:142) at com.ibm.db2.jcc.c.jb.a(jb.java:43) at com.ibm.db2.jcc.c.w.a(w.java:30) at com.ibm.db2.jcc.c.cc.g(cc.java:160) at com.ibm.db2.jcc.a.hd.n(hd.java:1215) at com.ibm.db2.jcc.a.id.gb(id.java:1780) at com.ibm.db2.jcc.a.id.d(id.java:2255) at com.ibm.db2.jcc.a.id.X(id.java:505) at com.ibm.db2.jcc.a.id.executeQuery(id.java:488) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:107) at org.hibernate.loader.Loader.getResultSet(Loader.java:1183) at org.hibernate.loader.Loader.doQuery(Loader.java:363) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203) at org.hibernate.loader.Loader.doList(Loader.java:1499) ... 6 more

    Hibernate JIRA | 7 years ago | kalyan buddala
    org.hibernate.exception.SQLGrammarException: could not execute query
  3. 0

    JDBC type 4 and OpenOffice.org

    Google Groups | 1 decade ago | LorneSunley
    com.ibm.db2.jcc.a.SqlException: DB2 SQL error: SQLCODE: -243, SQLSTATE: 36001, SQLERRMC: SQL_CURSH200C1
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. com.ibm.db2.jcc.a.SqlException

      DB2 SQL error: SQLCODE: -171, SQLSTATE: 42815, SQLERRMC: 2;-

      at com.ibm.db2.jcc.a.hd.e()
    2. IBM DB2
      hd.a
      1. com.ibm.db2.jcc.a.hd.e(hd.java:1659)
      2. com.ibm.db2.jcc.a.hd.a(hd.java:1235)
      3. com.ibm.db2.jcc.a.hd.a(hd.java:1221)
      3 frames
    3. com.ibm.db2
      cc.g
      1. com.ibm.db2.jcc.c.jb.h(jb.java:142)
      2. com.ibm.db2.jcc.c.jb.a(jb.java:43)
      3. com.ibm.db2.jcc.c.w.a(w.java:30)
      4. com.ibm.db2.jcc.c.cc.g(cc.java:160)
      4 frames
    4. IBM DB2
      id.executeQuery
      1. com.ibm.db2.jcc.a.hd.n(hd.java:1215)
      2. com.ibm.db2.jcc.a.id.gb(id.java:1780)
      3. com.ibm.db2.jcc.a.id.d(id.java:2255)
      4. com.ibm.db2.jcc.a.id.X(id.java:505)
      5. com.ibm.db2.jcc.a.id.executeQuery(id.java:488)
      5 frames
    5. Hibernate
      CustomLoader.list
      1. org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:107)
      2. org.hibernate.loader.Loader.getResultSet(Loader.java:1183)
      3. org.hibernate.loader.Loader.doQuery(Loader.java:363)
      4. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
      5. org.hibernate.loader.Loader.doList(Loader.java:1499)
      6. org.hibernate.loader.Loader.list(Loader.java:1482)
      7. org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103)
      7 frames
    6. Hibernate
      SQLQueryImpl.list
      1. org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1333)
      2. org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:146)
      2 frames
    7. com.hibernate
      ExceptionTest.main
      1. com.hibernate.ExceptionTest.getDateDifference(ExceptionTest.java:219)
      2. com.hibernate.ExceptionTest.main(ExceptionTest.java:43)
      2 frames