SQL/MX Programming Manual for Java

SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java523726-003
3-56
Passing Iterators as Parameters
// Retrieve rows and assign columns while next() returns true
while (iter.next()) {
if (iter.Salary() < avgsalary) {
#sql {UPDATE samdbcat.persnl.employee
SET salary = 1.1 * salary
WHERE CURRENT OF :iter};
}
}
iter.close();
// Reconstruct the iterator iter so that it contains
// the updated salaries
#sql namiter = {SELECT last_name, salary
FROM samdbcat.persnl.employee};
// Retrieve rows while next() returns true
while (iter.next()) {
empname = iter.Last_Name();
salary = iter.Salary();
System.out.println(empname + " earns " + salary);
}
iter.close();
Passing Iterators as Parameters
Both positioned and named iterators are Java objects, so you can pass them as
parameters just like other Java objects. The iterator class is a type that you can use as
a formal argument. You can use the sqlj.runtime.PositionedIterator,
sqlj.runtime.NamedIterator, and sqlj.runtime.ResultSetIterator
classes as data types that are independent of the iterator. For more information about
these classes, see:
sqlj.runtime.PositionedIterator Interface on page B-6
sqlj.runtime.NamedIterator Interface on page B-5
sqlj.runtime.ResultSetIterator Interface on page B-7
Converting Between SQLJ Iterators and JDBC Result Sets
In an SQLJ program, you can convert between SQLJ iterators and JDBC results sets:
Creating an Iterator From a JDBC Result Set on page 3-56
Creating a JDBC Result Set From an Iterator on page 3-57
Creating an Iterator From a JDBC Result Set
You can create an iterator from a JDBC result set with the SQLJ CAST statement. For
the syntax of an SQLJ CAST statement, see Iterator Conversion Clause on page A-6.