DB2 SQL Error: SQLCODE=-103, SQLSTATE=42604, S...

报的异常

org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute query; bad SQL grammar [select t.rule_code as ruleCode,t.run_time as runTime,t.err_code as errCode,t.err_msg as errMsg from  code_rep_rule_log t where t.rule_code=701_21-1 and t.run_time=2013-07-05]; nested exception is com.ibm.db2.jcc.b.eo: DB2 SQL Error: SQLCODE=-103, SQLSTATE=42604, SQLERRMC=701_21, DRIVER=3.53.95
com.ibm.db2.jcc.b.eo: DB2 SQL Error: SQLCODE=-103, SQLSTATE=42604, SQLERRMC=701_21, DRIVER=3.53.95
at com.ibm.db2.jcc.b.bd.a(bd.java:676)
at com.ibm.db2.jcc.b.bd.a(bd.java:60)
at com.ibm.db2.jcc.b.bd.a(bd.java:127)
at com.ibm.db2.jcc.b.gm.c(gm.java:2484)
at com.ibm.db2.jcc.b.gm.d(gm.java:2461)
at com.ibm.db2.jcc.b.gm.a(gm.java:1962)
at com.ibm.db2.jcc.t4.db.g(db.java:138)
at com.ibm.db2.jcc.t4.db.a(db.java:38)
at com.ibm.db2.jcc.t4.t.a(t.java:32)
at com.ibm.db2.jcc.t4.sb.h(sb.java:141)
at com.ibm.db2.jcc.b.gm.bb(gm.java:1933)
at com.ibm.db2.jcc.b.hm.ec(hm.java:2558)
at com.ibm.db2.jcc.b.hm.e(hm.java:3259)
at com.ibm.db2.jcc.b.hm.Rb(hm.java:583)
at com.ibm.db2.jcc.b.hm.executeQuery(hm.java:557)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
at org.hibernate.loader.Loader.doQuery(Loader.java:391)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:112)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1414)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:153)
at com.krm.dao.hibernate.BaseDAOHibernate$6.doInHibernate(BaseDAOHibernate.java:492)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:356)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:329)
at com.krm.dao.hibernate.BaseDAOHibernate.list(BaseDAOHibernate.java:495)
at com.krm.dao.hibernate.BaseDAOHibernate.list(BaseDAOHibernate.java:457)
at com.krm.dao.hibernate.BaseDAOHibernate.list(BaseDAOHibernate.java:452)
at com.krm.standard.applog.dao.hibernate.AppLogDAOHibernate.getAppLogByCT(AppLogDAOHibernate.java:20)
at com.krm.standard.applog.dao.TestDemo.testcon(TestDemo.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)



首先查了错误代码对应的问题是 -103 42604 无效数学文字,但是没有找到错误!最后找同事帮忙查看,原因出在sql语句上!
错误语句:
String sql = "select t.rule_code as ruleCode,t.run_time as runTime,t.err_code as errCode,t.err_msg as errMsg from  code_rep_rule_log t where t.rule_code="+ruleCode+" and t.run_time="+runTime+"";

修改后
String sql = "select t.rule_code as ruleCode,t.run_time as runTime,t.err_code as errCode,t.err_msg as errMsg from  code_rep_rule_log t where t.rule_code='"+ruleCode+"' and t.run_time='"+runTime+"'";

因为数据库表中对应的字段是varchar类型的,需要用单引号引起来!

你可能感兴趣的:(db2,SQLCODE=-103)