SQL/MX Programming Manual for Java
SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java—523726-003
3-51
Named Iterator
the next row of the result set. If the last attempt to fetch a row fails (that is, there are no 
more rows left in the result set), endFetch() returns true. 
Note that the end-of-data handling of iterators differs from testing for the end-of-data 
condition in embedded SQL programs in C or COBOL. When you reach the end of 
data in a cursor (or result set), SQLSTATE returns 02000. In an embedded SQL 
program in C or COBOL, you must code if (SQLSTATE = "02000") after each 
fetch to determine if you have read a row or not. For more information, see the 
SQL/MX Programming Manual for C and COBOL. In an SQLJ program, check for the 
end-of-data condition in a positioned iterator by coding endFetch(). 
Using the close() Method
Use the close() method from the generated iterator class PosIter to close an 
iterator after using it. Because iterators hold database resources, you should explicitly 
close an iterator that you are no longer using rather than wait for garbage collection to 
free resources.
Named Iterator
For a named iterator, you specify names for each of the iterator columns. The columns 
of the iterator declaration are bound to the columns of the result set by name. The 
names of the iterator columns must match the names of the corresponding columns in 
the result set of the query.
Declaring a Named Iterator Class
Declare an iterator as named by using an iterator declaration clause, which specifies a 
list of column names and Java data types corresponding to columns in the result set. 
For the syntax, see the Iterator Declaration Clause on page A-2.
The column names in the iterator declaration clause must be valid Java identifiers and 
must match the column names in the result set. However, the match is not case-
sensitive. If the columns in the SELECT statement are not valid Java identifiers (for 
example, Java reserved words), use AS clauses in the SELECT statement to provide 
acceptable names. For more information, see Using AS Clauses on page 3-52.
Place the iterator declaration clause where an SQLJ declaration clause is allowed in an 
SQLJ program. The iterator declaration clauses usually appear at the beginning (or the 
top-level scope) of an SQLJ source file. The placement of the iterator declaration 
clause affects the visibility of the iterator class for other classes. For more information, 
see Placement of Declaration Clauses on page 3-2. 
In this example, an iterator declaration clause names a named iterator class NamIter: 
#sql public iterator NamIter (String Last_Name, 
BigDecimal Salary);
The SQLJ translator replaces each iterator declaration clause with a Java definition of 
the iterator class in the Java source (.java) file. The iterator class implements the 










