Bootstrap

ssh c3po oracle存储过程传数组

java代码调用存储过程,在传入数组参数的时候用到多种取数据库连接的方式,这里我用的是:

  c3p0连接池,Spring 2.5,Hibernate 3.2.3

但是却一直有这种异常,

 

java.lang.ClassCastException: com.mchange.v2.c3p0.impl.NewProxyConnection cannot be cast to oracle.jdbc.OracleConnection
    at com.becom.reports.service.ext.impl.RptSrvRoleManagerExt.saveRoleFunc(RptSrvRoleManagerExt.java:241)
    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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
    at $Proxy13.saveRoleFunc(Unknown Source)
    at com.becom.reports.webapp.action.rolefunc.RoleAction.doSaveRights(RoleAction.java:213)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

 

数据库为:Oracle 10g R2

 

因它们取连接的方式是原始的jdbc连接的代理实现,但是在代理实现转化为jdbc连接时发生失败,最后发现要修改这个异常也只需要一句话就可以了,

需要加入包

spring-1.2-rc1.jar

再在java文件中加入

import org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor;

最后将下面的连接方法

OracleConnection connection = (OracleConnection) preparedStatement.getConnection();

替换修改为:

C3P0NativeJdbcExtractor cp30NativeJdbcExtractor = new C3P0NativeJdbcExtractor();
OracleConnection connection = (OracleConnection)cp30NativeJdbcExtractor.getNativeConnection(preparedStatement.getConnection());

 

 

很轻松的便可把问题KO掉了,呵呵,开发中遇到的一些问题和解决方法分享一下,但愿开发的朋友们少走弯路!

;