commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Ray.Extern...@infineon.com>
Subject DBCP, Oracle and ClassCastException
Date Mon, 14 Feb 2005 16:44:27 GMT
Like many others I am trying to get at the wrapped OracleConnection
object in DBCP.  I have looked here in this forum as well as Sun's site.
I have seen and tried many solutions, but none have worked for me.  I am
trying to pass a 2D array to a CallableStatement and I can only
accomplish it if I use the OracleConnection object since I am using
Array Descriptors, part of the Oracle JDBC extensions.  So far I have
had to use non-pooled DriverManager connection object.

I am using Tomcat 5.0.28 with SUN 1.4.2 JDK, and commons DBCP 1.2.1.
Any help would be appreciated.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLWarning;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

import oracle.jdbc.driver.OracleConnection;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.dbcp.PoolableConnection;
...
public static synchronized Connection getDelegatingConnection(
            String dataSource) throws
SQLException,NamingException,Exception {
        
        final String JNDI_LOOKUP = "java:comp/env";
        
        Connection conn = null;
        OracleConnection oc = null;
        
        Context initCtx = new InitialContext();
        Context envCtx = (Context) initCtx.lookup(JNDI_LOOKUP);
        
        if (envCtx == null) {
            throw new Exception("No EnvironmentContextException");
        }
        
        DataSource ds = (DataSource) envCtx.lookup(dataSource);
        if (ds == null) {
            throw new Exception("No DatasourceException");
        }
        
        ((BasicDataSource)
ds).setAccessToUnderlyingConnectionAllowed(true);
                
        conn = ds.getConnection();
        if (conn == null) {
            throw new Exception("No ConnectionException");
        } 

         
        Connection dconn =
((PoolableConnection)ds.getConnection()).getDelegate();
//ClassCastException here
        
        if (dconn == null) {
            throw new Exception("No DelegatingConnectionException");
        }

        return dconn;
    }

Regards,

Jimmy Ray
(804)952-7284
ray.external2@infineon.com



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message