我有一个从存储过程中检索DB2游标的解决方案,但我正在寻找更好的方法。目前的解决方案如下所述: -
存储过程: -
CREATE OR REPLACE PROCEDURE Proc(c1 OUT SYS_REFCURSOR, c2 OUT SYS_REFCURSOR,
c3 OUT SYS_REFCURSOR, ....)
is
BEGIN
open c1 FOR select feild1,feild2,.... from RSPNSE_TABLE1;
open c2 FOR select feild1,feild2,.... from RSPNSE_TABLE2;
open c3 FOR select feild1,feild2,.... from RSPNSE_TABLE3;
open c4 FOR select feild1,feild2,.... from RSPNSE_TABLE4;
open c5 FOR select feild1,feild2,.... from RSPNSE_TABLE5;
// continue this i got least 30 tables
END;
java代码来检索这些如下所示的游标: -
public boolean callProc() throws Exception {
Connection conn = openConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
int rowCount = 0;
try {
String proc = "call Proc(?,?,?,?,.....)";
callableStatement = conn.prepareCall(proc);
callableStatement.registerOutParameter(1, DB2Types.CURSOR);
callableStatement.registerOutParameter(2, DB2Types.CURSOR);
callableStatement.registerOutParameter(3, DB2Types.CURSOR);
.....
.....
boolean results = callableStatement.execute();
rs = (ResultSet) callableStatement.getObject(1);
// retrieve data from resultset
rs = (ResultSet) callableStatement.getObject(2);
// retrieve data from resultset
......
......
} catch (Exception e) {
throw e;
}
return true;
}
我对此有以下问题,
注意:两者的个别答案都是例外。甚至指出我能阅读和实现的正确资源也是例外。