IBM DB2 Manual page 142

Table of Contents

Advertisement

Using a positioned iterator in an SQLJ application
Use a positioned iterator to refer to columns in a result table by their position in
the result set.
The steps in using a positioned iterator are:
1. Declare the iterator.
126
Application Programming Guide and Reference for Java
"Performing positioned UPDATE and DELETE operations in an SQLJ
application" on page 114
"Using a positioned iterator in an SQLJ application"
"Using scrollable iterators in an SQLJ application" on page 130
Related reference
"SQLJ iterator-declaration-clause" on page 285
"sqlj.runtime.NamedIterator interface" on page 298
You declare any result set iterator using an iterator declaration clause. This causes
an iterator class to be created that has the same name and attributes as the
iterator. For a positioned iterator, the iterator declaration clause specifies the
following information:
v The name of the iterator
v A list of Java data types
v Information for a Java class declaration, such as whether the iterator is
public or static
v A set of attributes, such as whether the iterator is holdable, or whether its
columns can be updated
The data type declarations represent columns in the result table and are
referred to as columns of the result set iterator. The columns of the result set
iterator correspond to the columns of the result table, in left-to-right order. For
example, if an iterator declaration clause has two data type declarations, the
first data type declaration corresponds to the first column in the result table,
and the second data type declaration corresponds to the second column in the
result table.
You need to specify Java data types in the iterators that closely match the
corresponding DB2 column data types. See "Java, JDBC, and SQL data types"
for a list of the best mappings between Java data types and DB2 data types.
You can declare an iterator in a number of ways. However, because a Java class
underlies each iterator, you need to ensure that when you declare an iterator,
the underlying class obeys Java rules. For example, iterators that contain a
with-clause must be declared as public. Therefore, if an iterator needs to be
public, it can be declared only where a public class is allowed. The following
list describes some alternative methods of declaring an iterator:
v As public, in a source file by itself
This is the most versatile method of declaring an iterator. This method lets
you use the iterator declaration in other code modules, and provides an
iterator that works for all SQLJ applications. In addition, there are no
concerns about having other top-level classes or public classes in the same
source file.
v As a top-level class in a source file that contains other top-level class
definitions
Java allows only one public, top-level class in a code module. Therefore, if
you need to declare the iterator as public, such as when the iterator includes
a with-clause, no other classes in the code module can be declared as public.

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents