Connecting Tech Pros Worldwide Forums | Help | Site Map

Need example for accessing Resultsets from COBOL DB2 Stored procedures from Java

Newbie
 
Join Date: Sep 2008
Posts: 2
#1: Sep 24 '08
Hi,

I would appreciate if any one provide any example code for accessing ResultSets( Cursor declared with Return ) from Java?


Thanks,

Sreeni

Newbie
 
Join Date: Aug 2008
Posts: 9
#2: Sep 29 '08

re: Need example for accessing Resultsets from COBOL DB2 Stored procedures from Java


Here is what I have used

Expand|Select|Wrap|Line Numbers
  1. String callQuery = "call " + pgmLibraryName + "/procName('" + inpParam + "')";
  2.  
  3. ResultSet rs  = new BidderUtility().execStrSQL(callQuery);
And the code for execStrSQL is

Expand|Select|Wrap|Line Numbers
  1. public  ResultSet execStrSQL(String s) throws SQLException
  2.     {
  3.  
  4.         ResultSet resultset = null;
  5.         java.sql.CallableStatement callablestatement = null;
  6.  
  7.         try
  8.         {
  9.             if (dbCon==null||!connected||dbCon.isClosed())
  10.             {
  11.                 connected = false;
  12.                 this.connect();
  13.             }
  14.  
  15.             callablestatement = dbCon.prepareCall(s, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
  16.             resultset = callablestatement.executeQuery();
  17.         }
  18.         catch(NullPointerException ex)
  19.         {
  20.  
  21.             ex.printStackTrace();
  22.         }
  23.         catch (SQLException sqlEx)
  24.         {
  25.             if (sqlEx.getSQLState() != null && sqlEx.getSQLState().equals("08003"))
  26.             {
  27.                 boolean retry=true;
  28.                 {
  29.                     if (iRetryCount++ <= MAX_RETRY)
  30.                     {
  31.                         if (this.doConnect()) retry=false;
  32.                     }
  33.                     else
  34.                     {
  35.                         retry=false;
  36.                     }
  37.                 }while(retry);
  38.  
  39.                 callablestatement = dbCon.prepareCall(s, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
  40.                 resultset = callablestatement.executeQuery();
  41.             }
  42.             else
  43.             {
  44.                 throw sqlEx;
  45.             }
  46.         }
  47.  
  48.         return resultset != null ? resultset : null;
  49.     }
In the above code datasource for connection has been used. You may replace is with simpler connection. Again there are some other detailed codes that you may replace.

Hope this helps.
sakumar9's Avatar
Expert
 
Join Date: Jan 2008
Location: Bangalore
Posts: 127
#3: Oct 1 '08

re: Need example for accessing Resultsets from COBOL DB2 Stored procedures from Java


I would strongly recomment you to visit SQLLIB/samples/ directory. Many samples in various languages are shipped with DB2. You will find samples for IBM cobol as well as mf cobol along with other languages.

Let me know if you have any difficulties in accessing them.

Regards
-- Sanjay
Reply