on 12-10-2015 5:04 PM
Hi
Our application uses a custom data source to manage the connections to the customer's Oracle database.
We need to use proprietary OracleConnection methos, so we cast the generic Connection JDBC to OracleConnection. Example:
@Stateless
public class TestEJB implements TestEJBLocal {
@Override
public void testDriver() throws Exception {
// The data source is obtained from the JNDI
DataSource ds = (DataSource)new InitialContext().lookup("jdbc/ORACLE_TEST");
// When casting the Connection a ClassCastException is thrown, and the code fails here
OracleConnection oc = (OracleConnection) ds.getConnection();
}
}
At line 12 of the above code, we get the following exception:
Caused by: java.lang.ClassCastException: Cannot cast class com.sap.engine.services.dbpool.cci.ConnectionHandle to interface oracle.jdbc.OracleConnection
We do understand why we are getting the class cast exception (it is explained in this connection management article).
What we don't know is how we can overcome this problem. We need to use an "oracle.jdbc.OracleConnection" object to access proprietary methods (we are dealing with Arrays and other objects).
Can you please suggest options to overcome this? Is some sort of configuration available at the datasource level?
thanks in advance.
Hi Evandro,
we had this problem years ago, so I'm not quite sure about it. But maybe you should just try this.
We added this to application-j2ee-engine.xml:
<reference reference-type="hard" prepend="true">
<reference-target provider-name="sap.com" target-type="library">Oracle6_11</reference-target>
</reference>
"Oracle6_11" is the resource name of the deployed oracle driver on our server. The "prepend" parameter is not known to the IDE but it is essential.
In Java code, we did this with the connection from the datasource:
final ConnectionHandle connHandle = (ConnectionHandle) connection;
final Connection conn = connHandle.getMetaData().getConnection();
final oracle.jdbc.OracleConnection oracleConn = ((oracle.jdbc.driver.OracleConnection) conn).getPhysicalConnection();
Greetings, Marion
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I did mean line 08 of the example code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.