chat box....

Tuesday, July 3, 2012

Writing a Java stored procedure to return result sets

You can write your Java stored procedures to return multiple query result sets to a client program.

Your stored procedure can return multiple query result sets to a client program if the following conditions are satisfied:
  •        The client supports the DRDA® code points that are used to return query result sets.     
  •        The value of DYNAMIC RESULT SETS in the stored procedure definition is greater than 0. 


 For each result set that you want to be returned, your Java stored procedure must perform the following actions:  

 For each result set, include an object of type java.sql.ResultSet[] or an array of an SQLJ iterator class in the parameter list for the stored procedure method.
  1. If the stored procedure definition includes a method signature, for each result set, include java.sql.ResultSet[] or the fully-qualified name of an array of a class that is declared as an SQLJ iterator in the method signature. These result set parameters must be the last parameters in the parameter list or method signature. Do not include a java.sql.ResultSet array or an iterator array in the SQL parameter list of the stored procedure definition.
  2. Execute a SELECT statement to obtain the contents of the result set.
  3. Retrieve any rows that you do not want to return to the client.
  4. Assign the contents of the result set to element 0 of the java.sql.ResultSet[] object or array of an SQLJ iterator class that you declared in step 1.
  5. Do not close the ResultSet, the statement that generated the ResultSet, or the connection that is associated with the statement that generated the ResultSet.


DB2® does not return result sets for ResultSets that are closed before the stored procedure terminates.

The following code shows an example of a Java stored procedure that uses an SQLJ iterator to retrieve a result set.


Figure 1. Java stored procedure that returns a result set
     
         package s1;

import sqlj.runtime.*;
import java.sql.*;
import java.math.*;
#sql iterator NameSal(String LastName, BigDecimal Salary);                 1
public class S1Sal
 
{
  public static void getSals(BigDecimal[] AvgSalParm,
                             java.sql.ResultSet[] rs)                      2
    throws SQLException
  {
    NameSal iter1;
    try
    {
      #sql iter1 = {SELECT LASTNAME, SALARY FROM EMP                       3
                      WHERE SALARY>0 ORDER BY SALARY DESC};
      #sql {SELECT AVG(SALARY) INTO :(AvgSalParm[0]) FROM EMP};            4
    }
    catch (SQLException e)
    { 
      System.out.println("SQLCODE returned: " + e.getErrorCode());
      throw(e);
    }
    rs[0] = iter1.getResultSet();                                          5
  }


Notes to Figure 1:

  1. This SQLJ clause declares the iterator named NameSal, which is used to retrieve the rows that will be returned to the stored procedure caller in a result set.
  2. The declaration for the stored procedure method contains declarations for a single passed parameter, followed by the declaration for the result set object.
  3. This SQLJ clause executes the SELECT to obtain the rows for the result set, constructs an iterator object that contains those rows, and assigns the iterator object to variable iter1.
  4. This SQLJ clause retrieves a value into the parameter that is returned to the stored procedure caller.
  5. This statement uses the getResultSet method to assign the contents of the iterator to the result set that is returned to the caller. 

 
}

Monday, May 28, 2012

Spring Integration

 Spring Integration provides an extension of the Spring programming model to support the well-known Enterprise Integration Patterns.


Grap knowledge in 10 mins


Don't u feel this stops your hungry...Here is a hands on example on this..!  Access Now


Tuesday, May 22, 2012

Java Thread Dumps

Grab knowledge on Thread Dumps.

                              Gain Here

Wednesday, February 29, 2012

Good Walkthrough on SPRING BATCH with Example

Spring Batch :

In this article, we will have an overview of Spring Batch which provides batch and bulk processing capabilities. The architecture is extremely robust and it provides parallel as well as scheduled batch processing. The API provides template and helper classes for repeatable and retryable operations which will be discussed in this article with suitable examples. The classes/interfaces in Spring Batch are not tied to a specified domain and thus it is possible to integrate an application in any business domain seamlessly. This article tries to explain the various concepts in a step-by-step fashion and examples are provided when necessary. This article assumes that the readers have a fair bit of understanding on Core Spring framework.




Access the stuff here....

Sunday, February 12, 2012

Spring Ws generating process(XSD to wsdl generation)

Access the below link to get the good tutorial on converting xsd file into wsdl.

ACCESS the tutorial here..

Friday, January 6, 2012

Using Mercurial with TortoiseHg

Do you know how to use Mercurial with TortoiseHg..............?

If you are unaware Click Here to read that tutorial.

Thursday, December 8, 2011

How Hibernate Applications are managed by JBoss AS ??

Developing Applications with JBoss and Hibernate:

In this two-part article, we will cover the following topics:

* A short introduction to Hibernate
* Setting up our proof of concept for the Hibernate project
* Reverse engineering a database schema into Hibernate POJOs and mapping files
* Deploying the application to JBoss AS
* Comparing the Hibernate technology with EJB 3 persistence (JPA).