我知道这是一个非常古老的问题。但我希望这会有所帮助。在这里,我传递了一个自定义类型数组,并期望得到一个自定义类型数组。
myJavaRequest req = new myJavaRequest();
req.setEmpId("940006614");
myJavaReqArray[0] = req;
List<myJavaResp> myJavaRespLst = new ArrayList<myJavaResp>();
try {
//fetch connection (this should be a OracleConnection class).
OracleConnection oraConn = (OracleConnection) getConnectionFromDB();
//Set the mappings -- what is the SQL Object type to Java class mappings when it comes to response.
Map map = oraConn.getTypeMap();
map.put("MYSCHEMA.SQLRESPDTO", Class.forName("com.myhome.myJavaResp"));
//Create the Array descriptor for the input array
ArrayDescriptor inputArrayDescr = ArrayDescriptor.createDescriptor("MYSCHEMA.MYREQDTOLIST", oraConn);
ARRAY inputArray = new ARRAY(inputArrayDescr, oraConn, spgPrefReqArray); //This is an Oracle ARRAY
//Prepare the Stored procedure call
OracleCallableStatement stmt = (OracleCallableStatement)oraConn.prepareCall("{ ? = call MYSCHEMA.PKG.SOME_SP(?) }");
stmt.registerOutParameter(1, OracleTypes.ARRAY, "MYSCHEMA.SQLRESPDTOLIST");
stmt.setArray(2, inputArray);
//Lets execute
stmt.execute();
//Fetch the Array of Objects that will have the set of expecting response java objects.
ARRAY outArray = ((OracleCallableStatement)stmt).getARRAY(1);
Object[] objects = (Object[])outArray.getArray(map);
if(null != objects && objects.length > 0){
for(int iIndex=0; iIndex<objects.length; iIndex++){
myJavaRespLst.add((myJavaResp)objects[iIndex]);
}
}
}