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

时间:2019-03-19 15:07:28

标签: java oracle weblogic 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.

2 个答案:

答案 0 :(得分:0)

在WebLogic控制台中,禁用数据类型的包装(在Connection Pool-> Advanced下,请参见here)。重新启动服务器,现在您将获得一个oracle.sql.CLOB对象,而不是weblogic.jdbc.wrapper.Clob_oracle_sql_CLOB一个对象。

编辑:对于特定的方法/类,您可以使用特定的供应商连接(getVendorConnection() method),该连接应返回未包装的对象。

答案 1 :(得分:0)

由于无法解开或投射对象,我最终在数据库中自行工作:

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;