OracleDataSource ClassCastException (correction)

Discussions

EJB programming & troubleshooting: OracleDataSource ClassCastException (correction)

  1. Sorry i've made a mistake in the code when making changes.

    I'm using weblogic 8.1

    the code is the following:
    ***********************************************
    OracleDataSource dataSource = (OracleDataSource)ctx.lookup("dataSourceIt3");
    OracleConnection con = (OracleConnection) dataSource.getConnection();
    ***********************************************
    Is there a way to obtain an OracleDataSource from the Pool.
    The first line throws a ClassCastException.
    Im using the driver oracle.jdbc.driver.OracleDriver.

    I would thank someones help
  2. Why are you trying to cast to an OrcaleDataSource. You are far better using the generic DataSource interface which hides actual database implementation details from your application code. E.g.

    DataSource dataSource = (DataSource)ctx.lookup("dataSourceIt3");
    Connection con = dataSource.getConnection();
  3. I agree it's not that recommended, but you can always try something like:

    log(dataSource.getClass().getName())

    And check the result.

    David
  4. Clarifying the problem[ Go to top ]

    I'm trying to obtain an OracleDataSource in order to obtain an OracleConnection.
    I need an OracleConnection to obtain an OraclePreparedStatement.
    I need an OraclePrepareStatetment to obtain an OracleResultSet and finally
    I need an OracleResultSet to obtain a BLOB object.

    I need to store video, fotos etc in the data base. I already tried with the java.sql.Blob, but when I try to use the setBytes method it doesn't work. So I used the putBytes(...) method only provided by the oracle BLOB. This method does work. I´ve made all this in a BMP, but the problem is that I need to share the same Data Base session with other CMPs in order to support transactions.

    I hope the problem is now clear.

    I would thank again someone's help.
  5. Problem solved[ Go to top ]

    Hi .. I've found a solution to my problem maybe it can be useful for someone else.

    Here it is:

    Weblogic provides some extensions for some data base drivers. I red the manual "Programming WebLogic JDBC" on chapter "Using Third-Party Drivers with
    WebLogic Server" and find the answer.

    You must import the following

    import weblogic.jdbc.vendor.oracle.*;

    and you can use blob like this:

    OracleThinBlob mDoc = (OracleThinBlob)rsConsulta.getBlob(1);
    mDoc.putBytes(1,pDoc.getFileData());

    Where pDoc.getFileData() returns a Byte[] with the file to store.

    Don´t use the Oracle classes use the java.sql.* and cast them to weblogic.jdbc.vendor.oracle.*

    Unfortunately weblogic does not provide all the method that Oracle does but I hope you can mess with that.

    Sorry for my english.