converting a java.lang.String to CLOB - Websphere

This is a discussion on converting a java.lang.String to CLOB - Websphere ; Hi, i want to convert java.lang.String to oracle.sql.CLOB object and need to insert it into my Oracle Database. I am getting ClassCast Exception at the time of creation of CLOB Exception :com.ibm.ws.rsadapter.jdbc.WSJdbcConnection here i get Connection con from jndi. oracle.sql.CLOB ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: converting a java.lang.String to CLOB

  1. converting a java.lang.String to CLOB

    Hi,

    i want to convert java.lang.String to oracle.sql.CLOB object and need to insert

    it into my Oracle Database.

    I am getting ClassCast Exception at the time of creation of CLOB

    Exception :com.ibm.ws.rsadapter.jdbc.WSJdbcConnection



    here i get Connection con from jndi.



    oracle.sql.CLOB newClob = oracle.sql.CLOB.createTemporary(con, false, oracle.sql.CLOB.DURATION_CALL);



    can any one please help me in this regard



    java: 1.4

    oracle: 9i

    Websphere 5.3v

  2. Re: converting a java.lang.String to CLOB

    mareedu_hari@rediffmail.com wrote:
    > Hi,
    > i want to convert java.lang.String to oracle.sql.CLOB object and need to insert
    > it into my Oracle Database.
    > I am getting ClassCast Exception at the time of creation of CLOB
    > Exception :com.ibm.ws.rsadapter.jdbc.WSJdbcConnection
    >
    > here i get Connection con from jndi.
    >
    > oracle.sql.CLOB newClob = oracle.sql.CLOB.createTemporary(con, false, oracle.sql.CLOB.DURATION_CALL);
    >
    > can any one please help me in this regard
    >
    > java: 1.4
    > oracle: 9i
    > Websphere 5.3v
    >

    You're not showing us any WebSphere code. What WebSphere code fails?
    That line of code doesn't get a connection.
    Ken

  3. Re: converting a java.lang.String to CLOB

    I have the same problem.

    It happen any time that you try to create an oracle temporary CLOB or BLOB.

    The oracle method is defined as BLOB.createTemporary(Connection con, boolean cache, in duration)



    Inside this method Oracle's JDBC driver casts the connection object to OracleConnection. This works fine when ever you don't use WAS datasource with connection pool.



    As soon as WAS datasoruce is use the cast becomes a problem because the WAS datasource returns a WAS specific connection wrapper WSjdbcConnection.



    The following code cab be added to a simple servlet to show the failure.

    boolean runningInWAS = true;

    if( runningInWAS ){

    Context context = null;

    try {

    context = new InitialContext();

    } catch(NamingException e) {

    throw new ServletException("Could not get Initial Context");

    }



    // datasource lookup

    try

    {

    DataSource datasource =

    (DataSource)context.lookup("java:comp/env/jdbc/WASDatasource");



    Connection conn = datasource.getConnection();

    //The following line trows and error when running in WebSphere env.

    BLOB sBlob = BLOB.createTemporary(conn, true, BLOB.DURATION_SESSION);

    conn.close();

    } catch(SQLException sql){



    } catch(NamingException e) {

    log.error("JNDI lookup failed for datasource for RM database: "

    + RMConstants.JNDI_DATASOURCE_RMDB, e);

    throw new ServletException("Could not get connection to Resource Manager datasource: "

    + RMConstants.JNDI_DATASOURCE_RMDB);

    }

    }else{ // running stand alone, is OK

    try{

    Class cObj = Class.forName("oracle.jdbc.pool.OracleDataSource");

    DataSource datasource = = (DataSource) cObj.newInstance();

    ((oracle.jdbc.pool.OracleDataSource) datasource).setServerName("host.svl.ibm.com");

    ((oracle.jdbc.pool.OracleDataSource) datasource).setDriverType("thin");

    ((oracle.jdbc.pool.OracleDataSource) datasource).setDatabaseName("myDB");

    ((oracle.jdbc.pool.OracleDataSource) datasource).setPortNumber(1521);

    ((oracle.jdbc.pool.OracleDataSource) datasource).setUser("scott");

    ((oracle.jdbc.pool.OracleDataSource) datasource).setPassword("tigger");



    BLOB sBlob = BLOB.createTemporary(datasource.getConnection(), true, BLOB.DURATION_SESSION);

    } catch(SQLException sql){

    }

    }



    I have seen a suggestion to use WSjdbcUtil.getNativeConnection(), but that has the problem I need to include WAS jar files in our build environment an it does not work when we deploy on other Application servers.



    Can any one provide a better workaround to this problem?

  4. Re: converting a java.lang.String to CLOB

    I found information about calling the PL/SQL function directly it works fine.



    This code works fine for me. NOTE: type has to be oracle.jdbc.OracleTypes.BLOB or

    oracle.jdbc.OracleTypes.CLOB



    private Object createTemporaryLOB(Connection conn, int type)

    throws SQLException

    {

    Object lob = null;

    CallableStatement createTemporaryStmt = conn.prepareCall("{ call DBMS_LOB.CREATETEMPORARY(?,TRUE)}");

    createTemporaryStmt.registerOutParameter(1, type);

    createTemporaryStmt.execute();

    lob = createTemporaryStmt.getObject(1);

    if( lob==null){

    log.error("Fail to create a temporary lob");

    }

    return lob;

    }

  5. Re: converting a java.lang.String to CLOB

    oracle.sql.CLOB lob = null;

    CallableStatement createTemporaryStmt = null;


    createTemporaryStmt = conn.prepareCall("{ call DBMS_LOB.CREATETEMPORARY(?,TRUE)}");



    createTemporaryStmt.registerOutParameter(1, oracle.jdbc.OracleTypes.CLOB);



    createTemporaryStmt.execute();


    Object obj = createTemporaryStmt.getObject(1);

    System.out.println("obj = "+obj);



    lob = (oracle.sql.CLOB)obj;// throws class cast exception


    The above code throws java.lang.ClassCastException at lob = (oracle.sql.CLOB)obj in jboss but it works perfectly in orion. But when trying to print obj it shows

    obj = oracle.sql.CLOB@fe676b so why is it not able to type cast in jboss. pls help

  6. Re: converting a java.lang.String to CLOB

    You might ask in a jboss newsgroup instead of a competing appserver's
    newsgroup :-)
    Ken

    ashokkumarpu@rediffmail.com wrote:
    > oracle.sql.CLOB lob = null;
    >
    > CallableStatement createTemporaryStmt = null;
    >
    >
    > createTemporaryStmt = conn.prepareCall("{ call DBMS_LOB.CREATETEMPORARY(?,TRUE)}");
    >
    >
    >
    > createTemporaryStmt.registerOutParameter(1, oracle.jdbc.OracleTypes.CLOB);
    >
    >
    >
    > createTemporaryStmt.execute();
    >
    >
    > Object obj = createTemporaryStmt.getObject(1);
    >
    > System.out.println("obj = "+obj);
    >
    >
    >
    > lob = (oracle.sql.CLOB)obj;// throws class cast exception
    >
    >
    > The above code throws java.lang.ClassCastException at lob = (oracle.sql.CLOB)obj in jboss but it works perfectly in orion. But when trying to print obj it shows
    >
    > obj = oracle.sql.CLOB@fe676b so why is it not able to type cast in jboss. pls help
    >


+ Reply to Thread