Unwrap to OracleConnection
16,602
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;
}
Author by
mariu
Updated on June 04, 2022Comments
-
mariu over 1 year
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.
-
Viruzzo about 12 yearsWhat exactly doesn't work? I suppose you get a ClassCastException, but where? If it's on the cast to OracleConnection, find out the real class of the object you get with wc.getUnderlyingConnection().
-
Paris almost 10 yearsThis works indeed, but be aware that you should always close the wrapper Connection and not the unwrapped OracleConnection as this will not release the connection back to the pool. Furthermore, you should not try to close the OracleConnection as this will result in a "connection already closed" exception.