IBM DB2 Manual page 135

Table of Contents

Advertisement

You can avoid a bind time error for a program like the one in Figure 36 on page
118 by specifying the bind option SQLERROR(CONTINUE). However, this
technique has the drawback that it causes the DB2 database manager to build a
package, regardless of the SQL errors that are in the program. A better technique is
to write the program so that there is a one-to-one mapping between tables in
positioned UPDATE or DELETE statements and iterator classes. Figure 37 shows
an example of how to do this.
#sql iterator Table2Iter(String);
#sql iterator Table1Iter(String);
public static void main ( String args[] )
{
...
Table2Iter iter2 = null;
#sql [ctxt] iter2 = { SELECT CHAR_COL2 FROM TABLE2 };
Table1Iter iter1 = null;
#sql [ctxt] iter1 = { SELECT CHAR_COL1 FROM TABLE1 };
...
doUpdate(iter1);
}
public static void doUpdate ( Table1Iter iter )
{
...
#sql [ctxt] { UPDATE TABLE1 ... WHERE CURRENT OF :iter };
...
}
public static void doUpdate ( Table2Iter iter )
{
...
#sql [ctxt] { UPDATE TABLE2 ... WHERE CURRENT OF :iter };
...
}
Figure 37. Static positioned UPDATE that succeeds
With this method of coding, each iterator class is associated with only one table.
Therefore, the DB2 bind process can always associate the positioned UPDATE
statement with a valid iterator.
Related tasks
"Performing positioned UPDATE and DELETE operations in an SQLJ
application" on page 114
Making batch updates in SQLJ applications
The IBM Data Server Driver for JDBC and SQLJ supports batch updates in SQLJ.
With batch updates, instead of updating rows of a table one at a time, you can
direct SQLJ to execute a group of updates at the same time.
You can include the following types of statements in a batch update:
v Searched INSERT, UPDATE, or DELETE statements
v CREATE, ALTER, DROP, GRANT, or REVOKE statements
v CALL statements with input parameters only
Unlike JDBC, SQLJ allows heterogeneous batches that contain statements with
input parameters or host expressions. You can therefore combine any of the
following items in an SQLJ batch:
v Instances of the same statement
Chapter 4. SQLJ application programming
119

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents