JDBC unable to cast PreparedStatement to OraclePreparedStatement

Discussion in 'Java' started by Eqbal Z, May 18, 2004.

  1. Eqbal Z

    Eqbal Z Guest

    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.
     
    Eqbal Z, May 18, 2004
    #1
    1. Advertising

  2. "Eqbal Z" <> wrote in message
    news:...
    > 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
     
    Silvio Bierman, May 18, 2004
    #2
    1. Advertising

  3. Eqbal Z

    Sudsy Guest

    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>
     
    Sudsy, May 18, 2004
    #3
  4. Eqbal Z

    Sudsy Guest

    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.
     
    Sudsy, May 18, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keith Wansbrough

    Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver

    Keith Wansbrough, Aug 16, 2004, in forum: Java
    Replies:
    0
    Views:
    756
    Keith Wansbrough
    Aug 16, 2004
  2. Betty
    Replies:
    1
    Views:
    9,871
    Juha Laiho
    May 21, 2005
  3. Jesus M. Salvo Jr.
    Replies:
    2
    Views:
    4,241
    robert
    Feb 11, 2006
  4. Replies:
    16
    Views:
    5,976
  5. Andreas Leitgeb
    Replies:
    18
    Views:
    1,852
    Andreas Leitgeb
    Jul 24, 2012
Loading...

Share This Page