IBM DB2 Manual page 146

Table of Contents

Advertisement

The following example shows an application with two concurrently open instances
of an iterator.
...
ResultSet myFunc(String empid) // Method to open an iterator and get a resultSet
{
}
// An application can call this method to get a resultSet for each
// employee ID. The application can process each resultSet separately.
...
ResultSet rs1 = myFunc("000100"); // Get employee record for employee ID 000100
...
ResultSet rs2 = myFunc("000200"); // Get employee record for employee ID 000200
Figure 43. Example of opening more than one instance of an iterator in a single application
As with any other iterator, you need to remember to close this iterator after the last
time you use it to prevent excessive storage consumption.
Using scrollable iterators in an SQLJ application
In addition to moving forward, one row at a time, through a result table, you
might want to move backward or go directly to a specific row. The IBM Data
Server Driver for JDBC and SQLJ provides this capability.
An iterator in which you can move forward, backward, or to a specific row is
called a scrollable iterator. A scrollable iterator in SQLJ is equivalent to the result
table of a database cursor that is declared as SCROLL.
Like a scrollable cursor, a scrollable iterator can be insensitive or sensitive. A
sensitive scrollable iterator can be static or dynamic. Insensitive means that changes
to the underlying table after the iterator is opened are not visible to the iterator.
Insensitive iterators are read-only. Sensitive means that changes that the iterator or
other processes make to the underlying table are visible to the iterator. Asensitive
means that if the cursor is a read-only cursor, it behaves as an insensitive cursor. If
it is not a read-only cursor, it behaves as a sensitive cursor.
If a scrollable iterator is static, the size of the result table and the order of the rows
in the result table do not change after the iterator is opened. This means that you
cannot insert into result tables, and if you delete a row of a result table, a delete
hole occurs. If you update a row of the result table so that the row no longer
qualifies for the result table, an update hole occurs. Fetching from a hole results in
an SQLException.
Important: Like static scrollable cursors in any other language, SQLJ static
scrollable iterators use declared temporary tables for their internal processing. This
means that before you can execute any applications that contain static scrollable
iterators, your database administrator needs to create a temporary database and
temporary table spaces for those declared temporary tables.
If a scrollable iterator is dynamic, the size of the result table and the order of the
rows in the result table can change after the iterator is opened. Rows that are
inserted or deleted with INSERT and DELETE statements that are executed by the
130
Application Programming Guide and Reference for Java
MyIter iter;
#sql iter = {SELECT * FROM EMPLOYEE WHERE EMPNO = :empid};
return iter.getResultSet();
Related concepts
"Data retrieval in SQLJ applications" on page 123

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents