Using OracleConnection in WebLogic Server
Sometimes you need the JDBC driver specific implementation of the Connection or Statement. If you use the Oracle JDBC driver, this might be useful for doing things like implementing Proxy User Authentication or using nested tables, etc.
Getting the Connection
The standard Java EE way to get a connection is through a DataSource. Here is the normal piece of code:
Since every Java EE Application Server is free to provide its own implementation of the Connection, you might not have the right class (ie. OracleConnection) and will get a ClassCastException.
Getting the OracleConnection
WebLogic Server provides some support to get the vendor connection from the JDBC driver in use. To get the OracleConnection from the DataSource use this piece of code:
The underlying class is called T4CConnection and can be cast to an OracleConnection without any problems. If you, in any case, get a ClassCastException, you need to check your EAR or WAR packaging. If the Oracle JDBC libraries are included, remove them and everything should work like a charm.