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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rsreeni
    New Member
    • Sep 2008
    • 2

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

    Hi,

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


    Thanks,

    Sreeni
  • giffy
    New Member
    • Aug 2008
    • 9

    #2
    Here is what I have used

    Code:
    String callQuery = "call " + pgmLibraryName + "/procName('" + inpParam + "')";
    
    ResultSet rs  = new BidderUtility().execStrSQL(callQuery);
    And the code for execStrSQL is

    Code:
    public  ResultSet execStrSQL(String s) throws SQLException
    	{
    
    		ResultSet resultset = null;
    		java.sql.CallableStatement callablestatement = null;
    
    		try
    		{
    			if (dbCon==null||!connected||dbCon.isClosed())
    			{
    				connected = false;
    				this.connect();
    			}
    
    			callablestatement = dbCon.prepareCall(s, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    			resultset = callablestatement.executeQuery();
    		}
    		catch(NullPointerException ex)
    		{
    
    			ex.printStackTrace();
    		}
    		catch (SQLException sqlEx)
    		{
    			if (sqlEx.getSQLState() != null && sqlEx.getSQLState().equals("08003"))
    			{
    				boolean retry=true;
    				{
    					if (iRetryCount++ <= MAX_RETRY)
    					{
    						if (this.doConnect()) retry=false;
    					}
    					else
    					{
    						retry=false;
    					}
    				}while(retry);
    
    				callablestatement = dbCon.prepareCall(s, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    				resultset = callablestatement.executeQuery();
    			}
    			else
    			{
    				throw sqlEx;
    			}
    		}
    
    		return resultset != null ? resultset : null;
        }
    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.

    Comment

    • sakumar9
      Recognized Expert New Member
      • Jan 2008
      • 127

      #3
      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

      Comment

      Working...