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:

Caveat

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.
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

This is my blog for things I found useful during my work as Senior Solution Architect for Identity Management and Service-oriented Architecture at Oracle. All text expressed on this blog is my own opinion and not related to my employer.

Search

Top Tags
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today