有没有更好的方法从StoredProc检索多个CURSOR到Java?

时间:2015-09-11 17:17:50

标签: java database stored-procedures jdbc db2

我有一个从存储过程中检索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;
}

我对此有以下问题,

  1. 是否有从bat Proc返回多个游标的方法?
  2. 如果是,那么从可调用语句中检索它的java代码是什么?
  3. 注意:两者的个别答案都是例外。甚至指出我能阅读和实现的正确资源也是例外。

0 个答案:

没有答案