You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Mauricio Aristizabal <ar...@hotmail.com> on 2005/01/07 21:26:51 UTC

ClassCastException obtaining wrapped oracle connection

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:
http://forum.java.sun.com/thread.jspa?forumID=48&messageID=1326953&threadID=326031

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:@10.176.50.65:1521:SERV"
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: ClassCastException obtaining wrapped oracle connection

Posted by Jacob Kjome <ho...@visi.com>.
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.

Jake

 >-- 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:
 >>
 >http://forum.java.sun.com/thread.jspa?forumID=48&messageID=1326953&threadID=
 >326031
 >>
 >>
 >> 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:@10.176.50.65:1521:SERV"
 >> 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: commons-user-unsubscribe@jakarta.apache.org
 >For additional commands, e-mail: commons-user-help@jakarta.apache.org
 >
 >  


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: ClassCastException obtaining wrapped oracle connection

Posted by Dirk Verbeeck <di...@pandora.be>.
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.

-- 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:
> http://forum.java.sun.com/thread.jspa?forumID=48&messageID=1326953&threadID=326031 
> 
> 
> 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:@10.176.50.65:1521:SERV"
> 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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org