Apache Commons DBCP连接对象问题,org.apache.tomcat.dbcp.dbcp.PoolingDataSource中的Thread:ClassCastException $ PoolGuardConnectionWrapper [英] Apache Commons DBCP connection object problem, Thread: ClassCastException in org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper

查看:1804
本文介绍了Apache Commons DBCP连接对象问题,org.apache.tomcat.dbcp.dbcp.PoolingDataSource中的Thread:ClassCastException $ PoolGuardConnectionWrapper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache Commons DBCP( commons-dbcp.jar )连接池。

I am using Apache Commons DBCP (commons-dbcp.jar) Connection pool.

一旦我获得来自池的连接它包含在
org.apache.commons.dbcp.PoolingDataSource $ PoolGuardConnectionWrapper

Once I obtained a connection from the pool it is wrapped in the class org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.

我的要求是将一个字符串数组传递给Oracle中的pl / sql存储过程。

My requirement is to pass an array of Strings to pl/sql stored procedure in Oracle.

以下是我在以下代码片段中所做的事情:

Here is what I am doing in the following code snippet:

Connection dbConn = ConnectionManager.ds.getConnection();
//The above statement returns me an connection wrapped in the class
//org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.

org.apache.commons.dbcp.DelegatingConnection del = new org.apache.commons.dbcp.DelegatingConnection(dbConn.getConnection());
con = del.getInnermostDelegate();

cs = con.prepareCall("call SP_NAME(?,?,?,?)");
oracle.sql.ArrayDescriptor arDesc= oracle.sql.ArrayDescriptor.createDescriptor("ARRAY_NAME", (OracleConnection) con);

CallableStatement c_stmt = conn.prepareCall("begin update_message_ids_ota
(:x); end;" );
c_stmt.setArray( 1, array_to_pass );
c_stmt.execute();

在执行上述代码时,我得到以下异常:

On executing the above code, I get the following exception:


java.lang.ClassCastException:org.apache.commons.dbcp.PoolingDataSource $ PoolGuardConnectionWrapper无法在oracle.sql.ArrayDescriptor中强制转换为oracle.jdbc.OracleConnection
。 createDescriptor

java.lang.ClassCastException: org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to oracle.jdbc.OracleConnection at oracle.sql.ArrayDescriptor.createDescriptor

我试图在几乎所有的网站和论坛中找到解决方案,但无法得到满意的答案或同样的解决方案。

I tried to find out solution over this going throughout almost of the sites and forums, but couldn't get the satisfied answer or solution on the same.

推荐答案

默认情况下,DBCP不允许访问真正的底层数据库连接实例,所以你无法进入Oracle类。

By default, DBCP does not allow access to the "real" underlying database connection instance, so you cannot get to the Oracle class.

配置池,你可以设置

accessToUnderlyingConnectionAllowed = true

然后就可以了。

默认为false,这是一个潜在的危险操作,行为不端的程序可以做有害的事情。 (当保护连接已经关闭时关闭底层或继续使用它)小心并且只在需要直接访问驱动程序特定扩展时使用

Default is false, it is a potential dangerous operation and misbehaving programs can do harmful things. (closing the underlying or continue using it when the guarded connection is already closed) Be careful and only use when you need direct access to driver specific extensions

注意:不要关闭底层连接,只有原始连接。

NOTE: Do not close the underlying connection, only the original one.

这篇关于Apache Commons DBCP连接对象问题,org.apache.tomcat.dbcp.dbcp.PoolingDataSource中的Thread:ClassCastException $ PoolGuardConnectionWrapper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆