IBM DB2 Manual page 143

Table of Contents

Advertisement

v As a nested static class within another class
Using this alternative lets you combine the iterator declaration with other
class declarations in the same source file, declare the iterator and other
classes as public, and make the iterator class visible from other code modules
or packages. However, when you reference the iterator from outside the
nesting class, you must fully-qualify the iterator name with the name of the
nesting class.
v As an inner class within another class
When you declare an iterator in this way, you can instantiate it only within
an instance of the nesting class. However, you can declare the iterator and
other classes in the file as public.
You cannot cast a JDBC ResultSet to an iterator if the iterator is declared as
an inner class. This restriction does not apply to an iterator that is declared
as a static nested class. See "Use SQLJ and JDBC in the same application" for
more information on casting a ResultSet to a iterator.
2. Create an instance of the iterator class.
You declare an object of the positioned iterator class to retrieve rows from a
result table.
3. Assign the result table of a SELECT to an instance of the iterator.
To assign the result table of a SELECT to an iterator, you use an SQLJ
assignment clause. The format of the assignment clause for a positioned iterator
is:
#sql context-clause iterator-object={select-statement};
4. Retrieve rows.
Do this by executing FETCH statements in executable clauses in a loop. The
FETCH statements looks the same as a FETCH statements in other languages.
To test whether you have retrieved all rows, invoke the
PositionedIterator.endFetch method after each FETCH. endFetch returns a
boolean with the value true if the FETCH failed because there are no rows to
retrieve.
5. Close the iterator.
Use the PositionedIterator.close method to do this.
The following code demonstrates how to declare and use a positioned iterator. The
numbers to the right of selected statements correspond to the previously-described
steps.
Chapter 4. SQLJ application programming
127

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents