Error While inserting CLOB from Oracle using WebLogic Connection Pool, Works fine with out using pool - Weblogic

This is a discussion on Error While inserting CLOB from Oracle using WebLogic Connection Pool, Works fine with out using pool - Weblogic ; When I try to write a clob from Oracle, I receive "java.lang.ClassCastException" This error occurs only for CLOB Type and only if I try to connect to Oracle using WebLogic Jdbc Driver/Oracle POOL. I can write CLOB or any other ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Error While inserting CLOB from Oracle using WebLogic Connection Pool, Works fine with out using pool

  1. Error While inserting CLOB from Oracle using WebLogic Connection Pool, Works fine with out using pool


    When I try to write a clob from Oracle, I receive "java.lang.ClassCastException"


    This error occurs only for CLOB Type and only if I try to connect to
    Oracle using WebLogic Jdbc Driver/Oracle POOL.


    I can write CLOB or any other data using direct JDBC
    connection to ORacle with out any problem.



    Note :

    ... = (OracleResultSet)rs).getCLOB(1);

    statement cause problem.

    please help me...

    Thank you.


  2. Re: Error While inserting CLOB from Oracle using WebLogic ConnectionPool, Works fine with out using pool

    The problem is that you have to deal with Weblogic classes when you use a pool. We
    have code for updating CLOB's that works for both a straight Oracle connection or a
    Weblogic pool connection. Here it is:

    Usage:

    PreparedStatement stmt = con.prepareStatement("select clob_column from table");
    ResultSet rs = stmt.executeQuery();
    setCLOBFromString(rs.getClob(1), "New Value"); // or
    setCLOBFromString(rs.getObject(1), "New Value");


    // Update a CLOB in the database. Since Weblogic's CLOB API does not appear to
    offer
    // a way to TRIM a clob when an update makes the CLOB smaller, the remaining space
    // is filled with blanks.

    public static void setCLOBFromString(Object obj, String str) throws SQLException
    {
    try {

    int old_length = new Long(((java.sql.Clob)obj).length()).intValue();
    int new_length = str.length();

    Syslog.debug(DBAgent.class, "The current CLOB length is " + old_length + ", the
    new length = " + new_length );

    Writer out = null;

    if (obj instanceof oracle.sql.CLOB) {
    out = ((oracle.sql.CLOB)obj).getCharacterOutputStream();
    } else {
    out = ((weblogic.jdbc.common.OracleClob)obj).getCharacte rOutputStream();
    }

    out.write( str.toCharArray() );

    // Pad the string with spaces if a previous version was larger then this version
    for(int i = new_length; i < old_length; i++)
    out.write( " " );

    out.flush();
    out.close();

    // Cut off any extraneous length of the CLOB, if possible
    if (obj instanceof oracle.sql.CLOB && new_length < old_length) {
    ((oracle.sql.CLOB)obj).trim(new_length);
    }

    } catch (IOException ex) {
    throw new SQLException(ex.toString());
    }
    }


    I think I noticed that Java 1.4 offers ways to update CLOBs via the java.sql.Clob
    interface, so then our vendor-specific troubles might be over...

    Good luck,

    Joop Kaashoek


    SeungRyul Park wrote:

    > When I try to write a clob from Oracle, I receive "java.lang.ClassCastException"
    >
    > This error occurs only for CLOB Type and only if I try to connect to
    > Oracle using WebLogic Jdbc Driver/Oracle POOL.
    >
    > I can write CLOB or any other data using direct JDBC
    > connection to ORacle with out any problem.
    >
    > Note :
    >
    > ... = (OracleResultSet)rs).getCLOB(1);
    >
    > statement cause problem.
    >
    > please help me...
    >
    > Thank you.
    >



  3. Re: Error While inserting CLOB from Oracle using WebLogic Connection Pool, Works fine

    I've resolved this problem using java.sql.Clob. But when you want to write, you need to cast to OracleThinClob

    for more info and examples: http://www.dosideas.com/wiki/CLOB_de_Oracle_en_Weblogic

  4. Re: Error While inserting CLOB from Oracle using WebLogic Connection Pool, Works fine

    Try the in built programme in XP. Copy everything you want to burn and paste the same on the CD writer drive. Then use the option(under CD writing tasks) write these files to the CD.

  5. Re: Error While inserting CLOB from Oracle using WebLogic ConnectionPool, Works fine

    Quote Originally Posted by unix View Post
    The problem is that you have to deal with Weblogic classes when you use a pool. We
    have code for updating CLOB's that works for both a straight Oracle connection or a
    Weblogic pool connection. Here it is:

    Usage:

    PreparedStatement stmt = con.prepareStatement("select clob_column from table");
    ResultSet rs = stmt.executeQuery();
    setCLOBFromString(rs.getClob(1), "New Value"); // or
    setCLOBFromString(rs.getObject(1), "New Value");


    // Update a CLOB in the database. Since Weblogic's CLOB API does not appear to
    offer
    // a way to TRIM a clob when an update makes the CLOB smaller, the remaining space
    // is filled with blanks.

    public static void setCLOBFromString(Object obj, String str) throws SQLException
    {
    try {

    int old_length = new Long(((java.sql.Clob)obj).length()).intValue();
    int new_length = str.length();

    Syslog.debug(DBAgent.class, "The current CLOB length is " + old_length + ", the
    new length = " + new_length );

    Writer out = null;

    if (obj instanceof oracle.sql.CLOB) {
    out = ((oracle.sql.CLOB)obj).getCharacterOutputStream();
    } else {
    out = ((weblogic.jdbc.common.OracleClob)obj).getCharacte rOutputStream();
    }

    out.write( str.toCharArray() );

    // Pad the string with spaces if a previous version was larger then this version
    for(int i = new_length; i < old_length; i++)
    out.write( " " );

    out.flush();
    out.close();

    // Cut off any extraneous length of the CLOB, if possible
    if (obj instanceof oracle.sql.CLOB && new_length < old_length) {
    ((oracle.sql.CLOB)obj).trim(new_length);
    }

    } catch (IOException ex) {
    throw new SQLException(ex.toString());
    }
    }


    I think I noticed that Java 1.4 offers ways to update CLOBs via the java.sql.Clob
    interface, so then our vendor-specific troubles might be over...

    Good luck,

    Joop Kaashoek


    SeungRyul Park wrote:

    > When I try to write a clob from Oracle, I receive "java.lang.ClassCastException"
    >
    > This error occurs only for CLOB Type and only if I try to connect to
    > Oracle using WebLogic Jdbc Driver/Oracle POOL.
    >
    > I can write CLOB or any other data using direct JDBC
    > connection to ORacle with out any problem.
    >
    > Note :
    >
    > ... = (OracleResultSet)rs).getCLOB(1);
    >
    > statement cause problem.
    >
    > please help me...
    >
    > Thank you.
    >

    Hi,

    If we use new oracle jdbc drivers i.e. ojdbc5.jar then we don't have to take such effert to insert data into CLOB column and this also solves the class cast exception as well.

    Link to get this jar is,

    http://www.oracle.com/technology/sof...bc_111060.html


    Thanks,
    Hemant

    Thanks,
    Hemant

+ Reply to Thread