gpt4 book ai didi

java - Apache Commons DBCP 连接对象问题,线程 : ClassCastException in org. apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper

转载 作者:IT老高 更新时间:2023-10-28 21:14:15 26 4
gpt4 key购买 nike

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

一旦我从池中获得连接,它就会被包装在类 org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.

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

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

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();

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

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

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

最佳答案

默认情况下,DBCP 不允许访问“真正的”底层数据库连接实例,因此您无法访问 Oracle 类。

configuring游泳池,你可以设置

accessToUnderlyingConnectionAllowed = true

然后它就起作用了。

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.

关于java - Apache Commons DBCP 连接对象问题,线程 : ClassCastException in org. apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6489514/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com