2

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.

2 Answers 2

2

In your WebLogic console disable the wrapping of data types (under Connection Pool -> Advanced, see here). Restart the server and now you will get a oracle.sql.CLOB object instead of a weblogic.jdbc.wrapper.Clob_oracle_sql_CLOB one.

EDIT: For that specific method/class, you can use the specific vendor connection (getVendorConnection() method) which should return unwrapped objects.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for answer. I forgot to point I cannot disable that option because is already configured in production server. The code is prepared to handle determinate castings, but not this one.
Ok, I've edited my answer with a possible workaround.
1

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.