JDBC unable to cast PreparedStatement to OraclePreparedStatement

E

Eqbal Z

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.
 
S

Silvio Bierman

Eqbal Z said:
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
 
S

Sudsy

Eqbal said:
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>
 
S

Sudsy

Sudsy said:
Eqbal Z wrote:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top