Hi
I am using Apache Commons DBCP (commons-dbcp-1.2.2.jar) Connection pool.
Once i obtain a connection from the pool it is wrapped in the
class org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.
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 conn = ConnectionManager.ds.getConnection();
//The above statement returns me an connection wrapped in the class
//org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.
DelegatingConnection delegate_conn = new DelegatingConnection(conn);
//Obtain an object of class DelegatingConnection to get a reference to the
//actual underlying connection object using the getDelegate() method.
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "OTA_MSGIDS_STRING_ARRAY", delegate_conn.getDelegate() );
//Pass the actual underlying connection object to the above
//createDescriptor() method because the wrapped connection object as
//mentioned above is not accepted by the createDescriptor() method.
ARRAY array_to_pass = new ARRAY( descriptor, delegate_conn.getDelegate(), arrOta_Message_Ids_Offered );
//Pass the actual underlying connection object to the above
//ARRAY() constructor because the wrapped connection object as
//mentioned above is not accepted by the ARRAY() constructor.
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 cannot be cast to oracle.jdbc.OracleConnection
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:91) Obviously, the reason above is that even though i am sending the underlying connection object but the code in createDescriptor() method is
testing the connection object instance against an OracleConnection which it is not.
How can i use the Connection object returned by the Apache Commons DBCP connection pool to be compatible with the Connection object expected by
ArrayDescriptor.createDescriptor(
String str1, Connection conn1); method?
Any help is deeply appreciated.
[ December 08, 2008: Message edited by: Harvinder Thakur ]