Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unwrap to OracleConnection

I have this piece of code that used to run properly using JBoss 5.1, Oracle 11, ojdbc6.jar. I was getting the OracleConnection as needed.

InitialContext ic = new InitialContext();
DataSource  ds = ( DataSource ) ic.lookup( "java:/" + dataSource );
Connection con = ds.getConnection();       
OracleConnection conn = con.unwrap( OracleConnection.class );

Not anymore using JBoss 7, Oracle 11, ojdbc6.jar. It says like this:

Connection Not a wrapper class for Oracle Connection

If you have any idea, please help.

like image 334
mariu Avatar asked Oct 30 '25 20:10

mariu


1 Answers

I use "oracle.jdbc.pool.OracleConnectionPoolDataSource" as datasouce class in glassfish.

Use the class or find jboss class.

Edit and Try:

public OracleConnection getOracleConnection(Connection connection) throws SQLException {
    OracleConnection oconn = null;
    try {
        if (connection.isWrapperFor(oracle.jdbc.OracleConnection.class)) {
            oconn = (OracleConnection) connection.unwrap(oracle.jdbc.OracleConnection.class)._getPC();
        }
    } catch (SQLException e) {
        throw e;
    }
    return oconn;
}
like image 63
rslvn Avatar answered Nov 01 '25 13:11

rslvn