IBM DB2 Manual page 144

Table of Contents

Advertisement

#sql iterator ByPos(String,Date); // Declare positioned iterator ByPos 1
{
}
Figure 40. Example of using a positioned iterator
Multiple open iterators for the same SQL statement in an SQLJ
application
With the IBM Data Server Driver for JDBC and SQLJ, your application can have
multiple concurrently open iterators for a single SQL statement in an SQLJ
application. With this capability, you can perform one operation on a table using
one iterator while you perform a different operation on the same table using
another iterator.
For IBM Data Server Driver for JDBC and SQLJ type 2 connectivity to DB2 for
z/OS, support for multiple open iterators on a single SQL statement must be
enabled. To do that, set the db2.jcc.allowSqljDuplicateStaticQueries configuration
property to YES or true.
When you use concurrently open iterators in an application, you should close
iterators when you no longer need them to prevent excessive storage consumption
in the Java heap.
The following examples demonstrate how to perform the same operations on a
table without concurrently open iterators on a single SQL statement and with
concurrently open iterators on a single SQL statement. These examples use the
following iterator declaration:
import java.math.*;
#sql public iterator MultiIter(String EmpNo, BigDecimal Salary);
128
Application Programming Guide and Reference for Java
ByPos positer;
String name = null;
Date hrdate;
#sql [ctxt] positer =
{SELECT LASTNAME, HIREDATE FROM EMPLOYEE};
#sql {FETCH :positer INTO :name, :hrdate };
while (!positer.endFetch())
{ System.out.println(name + " was hired in " +
hrdate);
#sql {FETCH :positer INTO :name, :hrdate };
}
positer.close();
Related concepts
"SQL statement execution in SQLJ applications" on page 112
"Data retrieval in SQLJ applications" on page 123
Related tasks
"Using a named iterator in an SQLJ application" on page 124
"Performing positioned UPDATE and DELETE operations in an SQLJ
application" on page 114
"Using scrollable iterators in an SQLJ application" on page 130
Related reference
"SQLJ iterator-declaration-clause" on page 285
"sqlj.runtime.PositionedIterator interface" on page 299
// Declare object of ByPos class
// Declare host variables
// Assign the result table of the SELECT
// to iterator object positer
// Retrieve the first row
// Check whether the FETCH returned a row
// Fetch the next row
// Close the iterator
2
3
4
5

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents