问题描述
我正在使用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 theclass 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:
我试图在几乎所有的网站和论坛中找到解决方案,但无法得到满意的答案或同样的解决方案。
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,这是一个潜在的危险操作,行为不端的程序可以做有害的事情。 (当保护连接已经关闭时关闭底层或继续使用它)小心并且只在需要直接访问驱动程序特定扩展时使用
注意:不要关闭底层连接,只有原始连接。
NOTE: Do not close the underlying connection, only the original one.
这篇关于Apache Commons DBCP连接对象问题,org.apache.tomcat.dbcp.dbcp.PoolingDataSource中的Thread:ClassCastException $ PoolGuardConnectionWrapper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!