IBM DB2 Manual page 145

Table of Contents

Advertisement

Without the capability for multiple, concurrently open iterators for a single SQL
statement, if you want to select employee and salary values for a specific employee
number, you need to define a different SQL statement for each employee number,
as shown in Figure 41.
MultiIter iter1 = null;
String EmpNo1 = "000100";
#sql [ctx] iter1 =
{SELECT EMPNO, SALARY FROM EMPLOYEE WHERE EMPNO = :EmpNo1};
MultiIter iter2 = null;
String EmpNo2 = "000200";
#sql [ctx] iter2 =
{SELECT EMPNO, SALARY FROM EMPLOYEE WHERE EMPNO = :EmpNo2};
// Process with iter1
// Process with iter2
iter1.close();
iter2.close();
Figure 41. Example of concurrent table operations using iterators with different SQL
statements
Figure 42 demonstrates how you can perform the same operations when you have
the capability for multiple, concurrently open iterators for a single SQL statement.
...
MultiIter iter1 = openIter("000100"); // Invoke openIter to assign the result table
MultiIter iter2 = openIter("000200"); // Invoke openIter to assign the result
// Process with iter1
// Process with iter2
...
iter1.close();
iter2.close();
...
public MultiIter openIter(String EmpNo)
{
MultiIter iter;
#sql [ctxt] iter =
{SELECT EMPNO, SALARY FROM EMPLOYEE WHERE EMPNO = :EmpNo};
return iter;
}
Figure 42. Example of concurrent table operations using iterators with the same SQL
statement
Related concepts
"Data retrieval in SQLJ applications" on page 123
Multiple open instances of an iterator in an SQLJ application
Multiple instances of an iterator can be open concurrently in a single SQLJ
application. One application for this ability is to open several instances of an
iterator that uses host expressions. Each instance can use a different set of host
expression values.
// Iterator instance for retrieving
// data for first employee
// Employee number for first employee
// Assign result table to first iterator
// Iterator instance for retrieving
// data for second employee
// Employee number for second employee
// Assign result table to second iterator
// Close the iterators
// (for employee 100) to the first iterator
// table to the second iterator
// iter1 stays open when iter2 is opened
// Close the iterators
// Method to assign a result table
// to an iterator instance
// Method returns an iterator instance
Chapter 4. SQLJ application programming
129

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents