This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Websphere and the fly likes java.lang.ClassCastException when invoking jdbc stored procedure call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "java.lang.ClassCastException when invoking jdbc stored procedure call" Watch "java.lang.ClassCastException when invoking jdbc stored procedure call" New topic
Author

java.lang.ClassCastException when invoking jdbc stored procedure call

Shane Lee
Ranch Hand

Joined: Mar 19, 2005
Posts: 63
java.lang.ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcCallableStatement incompatible with oracle.jdbc.OracleCallableStatement

Websphere 6.1.0.17 ND
JEE1.4
Oracle 10G

Setup jdbc provider and datasource for oracle correctly, tested connection and its working fine on admin console.

In my application, lookup datasource to get connection, then have a call to the database connection on a stored function in oracle. It returns a REFCURSOR so my java line to return the result set is:
result = ((OracleCallableStatement)cs).getCursor(1);

This gives me the exception above.

i have been searching for solutions on this problem for nearly a day now and found one:
Error on datasource:
You can't count on the implmentation of the CallableStatement interface being the Oracle version, even though your underlying database is Oracle. When you use a WebSphere Data Source, neither the connection nor the objects it creates will cast to Oracle objects.

Because of these issues, IBM has provided a way to get at the "native" (in this case, Oracle) DataBase connection, and consequently at the native objects it creates. The help is in the form of the com.ibm.ws.rsadapter.jdbc.WSJdbcUtil class, which is in the WebSphere class path. Just use it's getNativeConnection method to get the underlying Oracle connection, and then the CallableStatement you produce from it will cast correctly. Example:


connection = (Connection) WSJdbcUtil.getNativeConnection((WSJdbcConnection)dataSource.getConnection());
OracleCallableStatement ocstmt = (OracleCallableStatement) connection.prepareCall(sql);


i do not want to have WAS libraries in my project though.

This jdbc call works fine locally, only a problem when i deploy my application on websphere.

is this a websphere configuration issue i am missing where i can change the implementation name for my jdbc provider or can i not use oracle calls whatsoever?

Thanks,
Shane.

Shane Lee
Ranch Hand

Joined: Mar 19, 2005
Posts: 63
Removed any oracle jbc callable statments and used java jdbc api classes instead, could not see any other way around it!
Anu Sathuluri
Greenhorn

Joined: May 11, 2010
Posts: 2
Shane,

How did you change your code to use jdbc APIs alone ?

What is the JDBC api equivalent of the code below ?

ResultSet crs = ((OracleCallableStatement) cstmt).getCursor(4);

thanks.
Shane Lee
Ranch Hand

Joined: Mar 19, 2005
Posts: 63
Hi Unu ,
Ha thats a while back since i worked on that! Looked at my existing code that i have on my laptop and this is a code snippet of how i called a stored procedure.


As you can see from the above comment, i use java.sql.CallableStatement now instead of OracleCallableStatement.
Anu Sathuluri
Greenhorn

Joined: May 11, 2010
Posts: 2
Thanks Shane. Change worked! You saved me hrs of investigation on the topic.

For other readers, i now used
ResultSet crs = (ResultSet) cstmt.getObject(4); // instead of ResultSet crs = ((OracleCallableStatement) cstmt).getCursor(4);

Shane Lee
Ranch Hand

Joined: Mar 19, 2005
Posts: 63
No worries Anu glad to be of help
Darrell Rials
Greenhorn

Joined: May 21, 2012
Posts: 1
Shane Lee wrote:Hi Unu ,
Ha thats a while back since i worked on that! Looked at my existing code that i have on my laptop and this is a code snippet of how i called a stored procedure.



As you can see from the above comment, i use java.sql.CallableStatement now instead of OracleCallableStatement.



Brilliant! Not only can I avoid using yet another Oracle-specific type, the code is cleaner and easier to understand. I was looking at some rather nasty changes to setting up the connection pool, which I had no assurance would work. Now if we could only get Oracle to (a) change their documentation on how to use a Cursor, and (b) allow returning pure result sets instead of having to return a cursor object.
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
Hi,

Just tried the more generic approach using:



but does not seem to have worked for me.I will still run some more tests and let you know about the results.


It worked for me this more generic approach in the end. I was having problems with duplicated entry in the classpath but it is fixed now and it is working with the generic approach I have mentioned here.

regards.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.ClassCastException when invoking jdbc stored procedure call
 
Similar Threads
calling a stored procedure in Jsp
Apache Commons DBCP connection object problem
ClassCastException in Weblogic 5.1 while using OracleCallableStatement
java.lang.ClassCastException
Oracle CallableStatement