3

I got the following code that works fine on OAS10, for fetching array of custom object from sql procedure:

Connection conn = null;
OracleCallableStatement stmt = null;
RequestsWrapper requestsWrapper = null;
conn = getConnection(DATASOURCE);
if (conn != null) {
    stmt = (OracleCallableStatement) conn.prepareCall("{call packageName.procedureName(?, ?, ?)}");
    stmt.registerOutParameter(3, OracleTypes.ARRAY, "V_ARRAY_OF_CUSTOM_OBJECTS");
    stmt.setString(1, in1);
    stmt.setString(2, in2);
    stmt.execute();
    ARRAY zahtjev = (ARRAY) cs.getArray(3);
    RequestsWrapper requestsWrapper = new RequestsWrapper();
    for (Object object : (Object[]) zahtjev.getArray()) {
        if (object != null) {
              CustomObject co = new CustomObject();
              Object[] attributes = ((STRUCT) object).getAttributes();
              co.setVarcharAttribute((String) attributes[0]);
              co.setNumericAttribute(((BigDecimal) attributes[1]).intValue());
              requestsWrapper.getObjectList().add(co);
       }
    }
}

and I have to migrate application to WLS 10.3.4. When I tried to execute existing code, I got an exception: cannot cast to oracle.sql.ARRAY. I found in WLS documentation:

For most extensions in the Oracle Thin driver, you can use the standard technique as described in Using API Extensions to JDBC Interfaces. However, the Oracle Thin driver does not provide public interfaces for its extension methods in the following classes:

oracle.sql.ARRAY
oracle.sql.STRUCT
oracle.sql.REF
oracle.sql.BLOB oracle.sql.CLOB

WebLogic Server provides its own interfaces to access the extension methods for those classes:

weblogic.jdbc.vendor.oracle.OracleArray weblogic.jdbc.vendor.oracle.OracleStruct weblogic.jdbc.vendor.oracle.OracleRef weblogic.jdbc.vendor.oracle.OracleThinBlob weblogic.jdbc.vendor.oracle.OracleThinClob

So, I followed the instructions and I got following code

Connection conn = null;
OracleCallableStatement stmt = null;
RequestsWrapper requestsWrapper = null;
conn = getConnection(DATASOURCE);
if (conn != null) {
    ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor("V_ARRAY_OF_CUSTOM_OBJECTS", conn);
    StructDescriptor structDescriptor = StructDescriptor.createDescriptor("T_CUSTOM_OBJECT", conn);
    stmt = (OracleCallableStatement) conn.prepareCall("{call packageName.procedureName(?, ?, ?)}");
    stmt.registerOutParameter(3, OracleTypes.ARRAY, "V_ARRAY_OF_CUSTOM_OBJECTS");
    stmt.setString(1, in1);
    stmt.setString(2, in2);
    stmt.execute();
    Array request = stmt.getArray(3);
    OracleArray requestOracleArray =  ((weblogic.jdbc.vendor.oracle.OracleArray)request).getOracleArray(); 
    Datum[] datumArray = ((weblogic.jdbc.vendor.oracle.OracleArray)request).getOracleArray();
    RequestsWrapper requestsWrapper = new RequestsWrapper();
    for (Datum object : datumArray) {
        if (object != null) {
           CustomObject co = new CustomObject();
           Object[] attributes = ((Struct) object).getAttributes();
           co.setVarcharAttribute((String) attributes[0]);
           co.setNumericAttribute(((BigDecimal) attributes[1]).intValue());
           requestsWrapper.getObjectList().add(co);
       }
    }
}

and numeric attribute is mapped OK, but instead of varchar2 attribute, I have '???'. Does anyone have similar problem?

Thanks in advance.

edit: i found on few pages info that orai18n.jar should be added to server classpath. but it doesn't work for me.

4

2 回答 2

8

最后, orai18n.jar 是解决方案。我必须将它包含在 weblogic 的 CLASSPATH 中,所以在 setDomainEnv.cmd 的 %MY_DOMAIN%\bin 文件夹中刚刚添加

设置 CLASSPATH=%WL_HOME%\server\ext\jdbc\oracle\11g\orai18n.jar

现在它可以工作了:)

于 2012-09-05T14:42:45.213 回答
0

有时这意味着您的 varchar2 字段中有 unicode 内容。请考虑一下。

于 2012-09-05T14:20:30.737 回答