IBM DB2 Manual page 157

Table of Contents

Advertisement

table.
#sql iterator EmpIter(String, java.sql.Date);
{
...
EmpIter iter=null;
#sql [connCtx] iter=
{SELECT LASTNAME, HIREDATE FROM EMPLOYEE};
ResultSet rs=iter.getResultSet();
while (rs.next())
{ System.out.println(rs.getString(1) + " was hired in " +
rs.getDate(2));
}
rs.close();
}
Figure 47. Converting an SQLJ iterator to a JDBC ResultSet
Notes to Figure 47:
Note
Description
1
This SQLJ clause executes the SELECT statement, constructs an iterator object that
contains the result table for the SELECT statement, and assigns the iterator object
to variable iter.
2
The getResultSet() method converts iterator iter to ResultSet rs.
3
The JDBC getString() and getDate() methods retrieve values from the ResultSet.
The next() method moves the cursor to the next row in the ResultSet.
4
The rs.close() method closes the SQLJ iterator as well as the ResultSet.
Rules and restrictions for using JDBC ResultSets in SQLJ applications: When you
write SQLJ applications that include JDBC result sets, observe the following rules
and restrictions:
v Before you can access the columns of a remote table by name, through either a
named iterator or an iterator that is converted to a JDBC ResultSet object, the
DB2 for z/OS DESCSTAT subsystem parameter must be set to YES.
v You cannot cast a ResultSet to an SQLJ iterator if the ResultSet and the iterator
have different holdability attributes.
A JDBC ResultSet or an SQLJ iterator can remain open after a COMMIT
operation. For a JDBC ResultSet, this characteristic is controlled by the IBM
Data Server Driver for JDBC and SQLJ property resultSetHoldability. For an
SQLJ iterator, this characteristic is controlled by the with holdability parameter
of the iterator declaration. Casting a ResultSet that has holdability to an SQLJ
iterator that does not, or casting a ResultSet that does not have holdability to an
SQLJ iterator that does, is not supported.
v Close a generated ResultSet object or the underlying iterator at the end of the
program.
Closing the iterator object from which a ResultSet object is generated also closes
the ResultSet object. Closing the generated ResultSet object also closes the
iterator object. In general, it is best to close the object that is used last.
v For the IBM Data Server Driver for JDBC and SQLJ, which supports scrollable
iterators and scrollable and updatable ResultSets, the following restrictions
apply:
– Scrollable iterators have the same restrictions as their underlying JDBC
ResultSet objects.
– You cannot cast a JDBC ResultSet that is not updatable to an SQLJ iterator
that is updatable.
1
2
3
4
Chapter 4. SQLJ application programming
141

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents