EasyManuals Logo

IBM DB2 User Manual

IBM DB2
585 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #144 background imageLoading...
Page #144 background image
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
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);
#sql iterator ByPos(String,Date); // Declare positioned iterator ByPos 1
{
ByPos positer; // Declare object of ByPos class 2
String name = null; // Declare host variables
Date hrdate;
#sql [ctxt] positer =
{SELECT LASTNAME, HIREDATE FROM EMPLOYEE}; 3
// Assign the result table of the SELECT
// to iterator object positer
#sql {FETCH :positer INTO :name, :hrdate }; 4
// Retrieve the first row
while (!positer.endFetch()) // Check whether the FETCH returned a row
{ System.out.println(name + " was hired in " +
hrdate);
#sql {FETCH :positer INTO :name, :hrdate };
// Fetch the next row
}
positer.close(); // Close the iterator 5
}
Figure 40. Example of using a positioned iterator
128 Application Programming Guide and Reference for Java

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM DB2 and is the answer not in the manual?

IBM DB2 Specifications

General IconGeneral
DeveloperIBM
Initial Release1983
LicenseProprietary
Written inC, C++
CategoryDatabase Management System (RDBMS)
Operating SystemLinux, Windows
Programming LanguagesC, C++
Data ModelsRelational
EditionsCommunity, Standard, Advanced
Key Featureshigh availability, scalability