分类: Java
2008-08-25 21:31:48
rg.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access; nested exception is org.hibernate.exception.DataException: could not execute query Caused by: org.hibernate.exception.DataException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:75) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java(Compiled Code)) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java(Inlined Compiled Code)) at org.hibernate.loader.Loader.list(Loader.java(Compiled Code)) at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java(Inlined Compiled Code)) at org.hibernate.impl.SessionImpl.list(SessionImpl.java(Compiled Code)) at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java(Compiled Code)) at com.skyon.mica.util.dao.hibernate.HibernateBaseDao.find(HibernateBaseDao.java:132) at sun.reflect.GeneratedMethodAccessor273.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code)) at java.lang.reflect.Method.invoke(Method.java(Compiled Code)) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java(Compiled Code)) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java(Inlined Compiled Code)) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java(Compiled Code)) at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java(Compiled Code)) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java(Compiled Code)) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java(Compiled Code)) at $Proxy130.find(Unknown Source) at com.skyon.mica.frontage.contract.manager.standard.StandardContractManager.getContract(StandardContractManager.java:144) at sun.reflect.GeneratedMethodAccessor660.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code)) at java.lang.reflect.Method.invoke(Method.java(Compiled Code)) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java(Compiled Code)) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java(Inlined Compiled Code)) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java(Compiled Code)) at com.skyon.mica.rule.intercept.MethodRuleInterceptor.invoke(MethodRuleInterceptor.java:51) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java(Compiled Code)) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java(Compiled Code)) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java(Compiled Code)) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java(Compiled Code)) at $Proxy215.getContract(Unknown Source) at com.skyon.mica.frontage.loanDueBill.web.action.LoanDueBillMaintenanceAction.showLoanDueBill(LoanDueBillMaintenanceAction.java:225) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java(Compiled Code)) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java(Compiled Code)) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code)) at java.lang.reflect.Method.invoke(Method.java(Compiled Code)) at com.opensymphony.xwork.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:365) at com.opensymphony.xwork.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java(Inlined Compiled Code)) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.xwork.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:137) at com.opensymphony.xwork.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java(Compiled Code)) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.xwork.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:115) at com.opensymphony.xwork.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java(Compiled Code)) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java(Compiled Code)) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java(Compiled Code)) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java(Compiled Code)) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.webwork.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:171) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java(Compiled Code)) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java(Compiled Code)) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.xwork.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:151) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java(Compiled Code)) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java(Compiled Code)) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java(Compiled Code)) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.skyon.mica.util.web.webwork.ExceptionToActionErrorInterceptor.intercept(ExceptionToActionErrorInterceptor.java:45) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:100) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java(Compiled Code)) at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:113) at com.opensymphony.webwork.dispatcher.DispatcherUtils.serviceAction(DispatcherUtils.java:233) at com.opensymphony.webwork.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java(Compiled Code)) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java(Compiled Code)) at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118) at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java(Compiled Code)) at com.opensymphony.webwork.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java(Compiled Code)) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java(Compiled Code)) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java(Compiled Code)) at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java(Compiled Code)) at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java(Compiled Code)) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java(Compiled Code)) at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java(Compiled Code)) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java(Compiled Code)) at org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java(Compiled Code)) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java(Compiled Code)) at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java(Compiled Code)) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java(Compiled Code)) at org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java(Compiled Code)) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java(Compiled Code)) at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java(Compiled Code)) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java(Compiled Code)) at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java(Compiled Code)) at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java(Compiled Code)) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java(Compiled Code)) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java(Compiled Code)) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java(Compiled Code)) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java(Compiled Code)) at com.skyon.mica.util.web.webwork.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java(Compiled Code)) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java(Compiled Code)) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java(Inlined Compiled Code)) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java(Compiled Code)) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java(Compiled Code)) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java(Inlined Compiled Code)) at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java(Compiled Code)) at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java(Compiled Code)) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java(Compiled Code)) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java(Compiled Code)) Caused by: com.ibm.db2.jcc.a.SqlException: DB2 SQL error: SQLCODE: -302, SQLSTATE: 22001, SQLERRMC: null at com.ibm.db2.jcc.a.hd.e(hd.java(Compiled Code)) at com.ibm.db2.jcc.a.hd.a(hd.java(Compiled Code)) at com.ibm.db2.jcc.c.jb.o(jb.java:655) at com.ibm.db2.jcc.c.jb.j(jb.java(Compiled Code)) at com.ibm.db2.jcc.c.jb.c(jb.java(Compiled Code)) at com.ibm.db2.jcc.c.w.c(w.java(Inlined Compiled Code)) at com.ibm.db2.jcc.c.cc.h(cc.java(Compiled Code)) at com.ibm.db2.jcc.a.hd.p(hd.java(Inlined Compiled Code)) at com.ibm.db2.jcc.a.id.d(id.java(Compiled Code)) at com.ibm.db2.jcc.a.id.X(id.java(Compiled Code)) at com.ibm.db2.jcc.a.id.executeQuery(id.java(Compiled Code)) at weblogic.jdbc.wrapper.PreparedStatement.executeQuery(PreparedStatement.java(Compiled Code)) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java(Compiled Code)) at org.hibernate.loader.Loader.getResultSet(Loader.java(Compiled Code)) at org.hibernate.loader.Loader.doQuery(Loader.java(Compiled Code)) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java(Compiled Code)) ... 108 more
-----------
发现输入主变量的值对于其在 SELECT、VALUES
或预编译语句中的使用来说太大。发生下列其中一种情况:
o SQL 语句中使用的相应主变量或参数标记被定义为字符串,但是输入主
变量包含的字符串太长。
o SQL 语句中使用的相应主变量或参数标记被定义为数字,但是输入主变
量包含的数值太大。
o C 语言以 NUL 终止的字符串主变量中丢失终止字符 NUL。
o 联合系统用户:在 联通 会话中,可能已违反特定于数据源的限制。
由于在 EXECUTE 或 OPEN 语句上的 SQLDA
中指定了不正确的主变量或不正确的 SQLLEN 值,所以发生此错误。
不能处理该语句。
用户响应:
确保输入主变量值的类型和长度是正确的。若输入主变量向参数标记提供值
,则使这些值与参数标记的隐含数据类型和长度相匹配。
联合系统用户:对于 联通 会话,确定哪一个数据源导致该错误(请参阅
Problem determination
guide,以了解标识失败数据源所要遵循的过程)。检查该数据源的 SQL
对话以确定违反了哪个特定限制,并根据需要来调整限制。
sqlcode : -302
sqlstate : 22001, 22003
------------------------------------------------------------------------------------------------
由此看来这个输入的查询条件错误
但页面已经做了判断.为什么还会出现这样的情况呢?
想到页面输入的时候用全码输入数字或者输中文字符,它们的字节码长度可能就会大于数据中定义的长度.
输入:"1234567890123456" 及输入中文测试,
所以报出的错误是一样的,证明已找到出错的原因
------------------------------------------------------------------------------------------------
但是在用工具查询的时候如:
//CUSTOM_BIT 为char(1)
select CUSTOM_BIT from product where CUSTOM_BIT='11111111111111'
这样后台是不会出错的,那这是为什么呢?为此又做测试
------------------------------------------------------------------------------------------------
//程序片断,当执行如下程序
public void Query() {
try {
//初始化数据库连接
this.in();
psm = con.prepareStatement("select CUSTOM_BIT from product where CUSTOM_BIT=?");
//CUSTOM_BIT字段为char(1),这里设值0是没有问题的.但是改成两位.在执行查询的时候就会报302的问题
psm.setString(1, "0");
//psm.setString(1, "01");
rs = psm.executeQuery();
while (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (Exception eq) {
eq.printStackTrace();
} finally {
this.closedate();
}
}
------------------------------------------------------------------------------------------------
而hibernate也是用这种方式去设置查询条件的..
而Statement和PreparedStatement之间的也有区别的,前者是执行完整的sql语句;后者是使用于定义格式,将sql中的where部分参数化,
对于大量相同的sql语句的执行,后者的效率高,而且可以防止sql注入,如 'userName or 1=1'将会被截断,与Statement都是真的.
所以当设置值的时候,PreparedStatement会判断输入的值是否超过数据库相应字段的长度,抛出错误.
发现输入主变量的值对于其在 SELECT、VALUES 或预编译语句中的使用来说太大
----------------------------------------------------------