commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <>
Subject Re: ClassCastException obtaining wrapped oracle connection
Date Mon, 10 Jan 2005 04:47:33 GMT
At 10:05 PM 1/9/2005 +0100, you wrote:
 >If your debugger or a conn.getClass().getName() gives you the same
 >classname but you are still getting a ClassCastException then there
 >are 2 versions of the oracle class loaded by a different classloader.
 >Probably one in WEB-INF/lib and one in a tomcat lib directory.
 >Make sure you only have one copy of the oracle jars in your classpath.

You can have as many copies as you want, although having one copy is 
certainly preferable for simplicity sake.  Just make sure that one of the 
many copies isn't in WEB-INF/lib in a container using parent-last 
classloading behavior as Tomcat does.  Or, more specifically, if you are 
using container managed connection pooling, make sure your driver 
implementation is not in a place where only your webapp can see it.  Tomcat 
internals must be able to see it as well.  In cases such as these, put your 
jar in the server's classpath, not the webapp's.


 >-- Dirk
 >Mauricio Aristizabal wrote:
 >> Hello all,
 >> I am trying to get the actual Oracle connection or statement from the
 >> dbcp pool, because I'm trying to use an oracle-specific feature
 >> (registerIndexTableOutParameter()), but I cannot cast the underlying
 >> connection even after using getInnermostDelegate() to get the wrapped
 >> connection.  I am using Tomcat 5.5 and whatever commons library came
 >> with it.
 >> I found this article with some helpful info:
 >> This is what I'm doing:
 >> OracleConnection oc = (OracleConnection) ((DelegatingConnection)
 >> c).getInnermostDelegate();
 >> If i break on that line my debugger shows the previous statement to return:
 >> oracle.jdbc.driver.OracleConnection@185e90f
 >> but I still get this exception when I continue:
 >> java.lang.ClassCastException: oracle.jdbc.driver.OracleConnection
 >> I've also tried to get innermost and cast statement itself:
 >> (oracle.jdbc.driver.OracleCallableStatement)((DelegatingCallableStatement)
 >> stmt).getInnermostDelegate()
 >> and again, debugger indicates I have what i want:
 >> oracle.jdbc.driver.OracleCallableStatement@16e1782
 >> but still exception is thrown:
 >> java.lang.ClassCastException: oracle.jdbc.driver.OracleCallableStatement
 >> This is what I want to do with the OracleStatement (works fine on
 >> Weblogic with same driver):
 >> ostmt.registerIndexTableOutParameter(3,1000, Types.VARCHAR, 300);
 >> Here's my context setup:
 >> <Context path="/OfferCode" docBase="OfferCode"
 >> debug="5" reloadable="true" crossContext="true">
 >> <Resource name="jdbc/devdb1b" auth="Container"
 >> type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
 >> url="jdbc:oracle:thin:@"
 >> username="asdfasdf" password="asdf" maxActive="20" maxIdle="10"
 >> maxWait="-1" accessToUnderlyingConnectionAllowed="true"/>
 >> <ResourceParams name="jdbc/devdb1b">
 >> <parameter>
 >> <name>accessToUnderlyingConnectionAllowed</name>
 >> <value>true</value>
 >> </parameter>
 >> </ResourceParams>
 >> </Context>
 >> Thanks in advance for lending us a hand.
 >> -Mauricio
 >To unsubscribe, e-mail:
 >For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message