Connection cannot be cast to oracle.jdbc.OracleConnection

The connection you are retrieving is probably a wrapped connection.

If you really need to get the underlying Oracle connection you should use:

if (connection.isWrapperFor(OracleConnection.class)){
   OracleConnection oracleConnection= connection.unwrap(OracleConnection.class);  
}else{
   // recover, not an oracle connection
}

The isWrapperFor and unwrap methods are available since Java 1.6, and should be meaningfully implemented by the A/S connection wrappers.


The connection pool usually has a wrapper around the real connection instance, that's why your cast fails.

What you are doing wouldn't work anyway, because the parameters in the properties instance are only checked when the connection is established. As you have a connection that is already active, it won't change anything.

You need tou use DBMS_APPLICATION_INFO.SET_CLIENT_INFO() in order to change this for an existing connection.