我知道这是一个非常古老的问题。但我希望这有助于。 这里我传递一个自定义类型数组,并返回期望的自定义类型数组。
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]);
}
}
}
将返回的jdbc数组结构转换为'List'。 jdbc中没有任何内容会为你执行POJO转换的任意值。 –
jtahlborn
实际上,列表是一个INOUT参数,我无法传递此参数。 –