Data Retrieval In Sqlj Applications - IBM DB2 Manual

Table of Contents

Advertisement

"sqlj.runtime.SQLNullException class" on page 314

Data retrieval in SQLJ applications

SQLJ applications use a result set iterator to retrieve result sets. Like a cursor, a
result set iterator can be non-scrollable or scrollable.
Just as in DB2 applications in other languages, if you want to retrieve a single row
from a table in an SQLJ application, you can write a SELECT INTO statement with
a WHERE clause that defines a result table that contains only that row:
#sql [myConnCtx] {SELECT DEPTNO INTO :hvdeptno
FROM DEPARTMENT WHERE DEPTNAME="OPERATIONS"};
However, most SELECT statements that you use create result tables that contain
many rows. In DB2 applications in other languages, you use a cursor to select the
individual rows from the result table. That cursor can be non-scrollable, which
means that when you use it to fetch rows, you move the cursor serially, from the
beginning of the result table to the end. Alternatively, the cursor can be scrollable,
which means that when you use it to fetch rows, you can move the cursor
forward, backward, or to any row in the result table.
This topic discusses how to use non-scrollable iterators. For information on using
scrollable iterators, see "Use scrollable iterators in an SQLJ application".
A result set iterator is a Java object that you use to retrieve rows from a result
table. Unlike a cursor, a result set iterator can be passed as a parameter to a
method.
The basic steps in using a result set iterator are:
1. Declare the iterator, which results in an iterator class
2. Define an instance of the iterator class.
3. Assign the result table of a SELECT to an instance of the iterator.
4. Retrieve rows.
5. Close the iterator.
There are two types of iterators: positioned iterators and named iterators. Postitioned
iterators extend the interface sqlj.runtime.PositionedIterator. Positioned
iterators identify the columns of a result table by their position in the result table.
Named iterators extend the interface sqlj.runtime.NamedIterator. Named iterators
identify the columns of the result table by result table column names.
Related concepts
"SQL statement execution in SQLJ applications" on page 112
"Multiple open iterators for the same SQL statement in an SQLJ application" on
page 128
"Multiple open instances of an iterator in an SQLJ application" on page 129
Related tasks
"Performing positioned UPDATE and DELETE operations in an SQLJ
application" on page 114
"Using a named iterator in an SQLJ application" on page 124
"Using a positioned iterator in an SQLJ application" on page 126
"Using scrollable iterators in an SQLJ application" on page 130
Related reference
"SQLJ iterator-declaration-clause" on page 285
Chapter 4. SQLJ application programming
123

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents