In DB2 SP, the result set's records will be fetched by JAVA directly. We do not need fetch the records in MF. What you need to do is Declare Cursor and Open the Cursor. That is enough. Fetch, your Java program will take care.
When JAVA issues, SQL CONNECT command a new DB2 thread is established between JAVA and Mainframe. After CONNECT statement, JAVA issues CALL statement to the DB2 Stored procedure with the Input Parameter Details.
When DB2 receives SQL CALL statement, it searches in SYSIBM.SYSPROCEDURES catalog table for a row associated with the Stored Procedure name. DB2 will obtain SP information and PARAMETER Details from SYSIBM.SYSROUTINES and SYSIBM.PARMS table.
After getting the SP details, it will get executed in WLM Established Address Space. This entire operation will be performed using Single thread which got established, when the CALL statement issued.
In our SP, we open only the cursor and since it is same thread JAVA can directly fetch the result set from the cursor.
Cursor should be declared with "WITH HOLD RETURN FOR" to retain the cursor ever after issing commit (in SP definition we can state COMMIT_ON_RETURN ON or COMMIT_ON_RETURN OFF).
Once JAVA fetched the result set, it will issue a command to Close the Connection. Thus the entire cycle is being performed from JAVA to MAINFRAME..