Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JDBC unable to cast PreparedStatement to OraclePreparedStatement

Reply
Thread Tools

JDBC unable to cast PreparedStatement to OraclePreparedStatement

 
 
Eqbal Z
Guest
Posts: n/a
 
      05-18-2004
Hi,

I am trying to cast PreparedStament and ResultSet to
OraclePreparedStatement and OracleResultSet respectively, but I get a
ClassCast Exception.
I am using Tomcat and oracle's jdbc driver (configured as JNDI
resource).
Any ideas?

Thanks.
 
Reply With Quote
 
 
 
 
Silvio Bierman
Guest
Posts: n/a
 
      05-18-2004

"Eqbal Z" <> wrote in message
news: om...
> Hi,
>
> I am trying to cast PreparedStament and ResultSet to
> OraclePreparedStatement and OracleResultSet respectively, but I get a
> ClassCast Exception.
> I am using Tomcat and oracle's jdbc driver (configured as JNDI
> resource).
> Any ideas?
>
> Thanks.


If you use JNDI Tomcat probably wrapped all the JDBC objects in wrapper
classes to do the connection pooling.

Silvio Bierman


 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      05-18-2004
Eqbal Z wrote:
> Hi,
>
> I am trying to cast PreparedStament and ResultSet to
> OraclePreparedStatement and OracleResultSet respectively, but I get a
> ClassCast Exception.
> I am using Tomcat and oracle's jdbc driver (configured as JNDI
> resource).
> Any ideas?
>
> Thanks.


That's because you didn't follow the directions I provided earlier.
You have to cast the Connection to an OracleConnection. Here's the
relevant code:
OralceConnection conn = (OracleConnection) DriverManager.getConnection(
dbConn, username, password );
OraclePreparedStatement stmt = (OraclePreparedStatement)
conn.prepareStatement( "..." );
....

As another poster noted, make sure that you're using the correct
Oracle class for the connection pool, i.e. something like this in
your struts-config.xml:

<data-sources>
<data-source type="oracle.jdbc.pool.OracleDataSource">
<set-property property="description"
value="Oracle Data Source"/>
<set-property property="driverClass"
value="oracle.jdbc.driver.OracleDriver"/>
<set-property property="url" value="..."/>
<set-property property="user" value="..."/>
<set-property property="password" value="..."/>
</data-source>
</data-sources>

 
Reply With Quote
 
Sudsy
Guest
Posts: n/a
 
      05-18-2004
Sudsy wrote:
> Eqbal Z wrote:

<snip>
> As another poster noted, make sure that you're using the correct
> Oracle class for the connection pool, i.e. something like this in
> your struts-config.xml:

<snip>

Oops...mixing metaphors. In a class which extends Action, just use
getDataSource().getConnection() and cast appropriately. The first
code snippet was for a stand-alone app.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JDBC, PreparedStatement and named parameters Andreas Leitgeb Java 18 07-24-2012 04:18 PM
JDBC PreparedStatement in a multi-threaded environment vk02720@gmail.com Java 16 11-28-2008 01:20 AM
stand-alone JMS, other JDBC operations, and transactions ( ActiveMQ + JOTM + JDBC operations ) Jesus M. Salvo Jr. Java 2 02-11-2006 06:33 PM
oracle.jdbc.OracleDriver vs oracle.jdbc.driver.OracleDriver Betty Java 1 05-21-2005 05:15 PM
Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver Keith Wansbrough Java 0 08-16-2004 07:31 PM



Advertisments
 



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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57