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.CLOBWebLogic 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.