IBM DB2 Manual page 131

Table of Contents

Advertisement

c. If the iterator is pointing to a row of the result table, execute an SQL
UPDATE... WHERE CURRENT OF :iterator-object statement in an executable
clause to update the columns in the current row. Execute an SQL DELETE...
WHERE CURRENT OF :iterator-object statement in an executable clause to
delete the current row.
For a named iterator, do this by performing the following actions in a loop:
a. Invoke the next method to move the iterator forward.
b. Test whether the iterator is pointing to a row of the result table by checking
whether next returns true.
c. Execute an SQL UPDATE... WHERE CURRENT OF iterator-object statement
in an executable clause to update the columns in the current row. Execute
an SQL DELETE... WHERE CURRENT OF iterator-object statement in an
executable clause to delete the current row.
6. Close the iterator.
Use the close method to do this.
The following code shows how to declare a positioned iterator and use it for
positioned UPDATEs. The numbers to the right of selected statements correspond
to the previously described steps.
First, in one file, declare positioned iterator UpdByPos, specifying that you want to
use the iterator to update column SALARY:
import java.math.*;
// Import this class for BigDecimal data type
#sql public iterator UpdByPos implements sqlj.runtime.ForUpdate
with(updateColumns="SALARY") (String, BigDecimal);
Figure 32. Example of declaring a positioned iterator for a positioned UPDATE
Then, in another file, use UpdByPos for a positioned UPDATE, as shown in the
following code fragment:
Chapter 4. SQLJ application programming
1
115

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents