Search code examples
javaoracleweblogicclob

How to get String from weblogic.jdbc.wrapper.Clob_oracle_sql_CLOB?


Environment: Oracle 11g, Weblogic 9.2, Java 4, driver: oracle.jdbc.OracleDriver

Context: I want to extract an xml value from a database and work with the result in Java, using the following select:

SELECT EXTRACT(XML_TEXT, 'PATH/TO/XML/VALUE/text()').getClobVal() AS VALUE 
FROM MYTBALE WHERE id =xxxx;

Problem: In the SQL Developer, I do can see the string retreived fine, but in Java:

  • If I use the getClobVal() function Weblogic returns a wrapped object of type weblogic.jdbc.wrapper.Clob_oracle_sql_CLOB which I'm not able to cast or unwrap.
  • If I don't use getClobVal() returns an oracle.sql.Opaque, which I'm not able to cast to anything either.

Code: Using getClobVal():

...
HashMap <String, Object> element = (HashMap) iter.next();
String value = (unwrap & cast in some way ) element.get("VALUE");
...

I can't find a way to get the string from that object, any ideas?

EDIT: I can't disable Weblogic wrapping. I'm thinking in making some workaround in database side to get a blob instead.


Solution

  • As I could not unwrap or cast the object, I ended up working in the database it self:

    create or replace procedure MANAGE_DOCUMENT(
      pSomeParam IN someTable.someColumn%TYPE,#if we need some param.
      pError OUT VARCHAR2
      )IS
      vResult BLOB;
      vDoc CLOB;
    
      begin
        pError := '';
    
        #extract base64 document
        SELECT EXTRACT(myColumn, 'xPath/to/the/element/text()').getClobVal()
        into vDoc
        FROM myTable WHERE someCondition;
    
        #check if doc exists
        IF vDoc IS NULL THEN
          pError :='Document not found';
        ELSE
          #decode and get blob
          vResult := utl_raw.cast_to_raw(vDoc);
          #do inserts or whatever        
          END IF;
        END IF; 
    end MANAGE_DOCUMENT;