IBM DB2 Manual page 136

Table of Contents

Advertisement

v Different statements
v Statements with different numbers of input parameters or host expressions
v Statements with different data types for input parameters or host expressions
v Statements with no input parameters or host expressions
When an error occurs during execution of a statement in a batch, the remaining
statements are executed, and a BatchUpdateException is thrown after all the
statements in the batch have executed. See "Retrieving information from a
BatchUpdateException" for information on how to process a BatchUpdateException.
To obtain information about warnings, use the Statement.getWarnings method on
the object on which you ran the executeBatch method. You can then retrieve an
error description, SQLSTATE, and error code for each SQLWarning object.
When a batch is executed implicitly because the program contains a statement that
cannot be added to the batch, the batch is executed before the new statement is
processed. If an error occurs during execution of the batch, the statement that
caused the batch to execute does not execute.
The basic steps for creating, executing, and deleting a batch of statements are:
1. Disable AutoCommit for the connection.
2. Acquire an execution context.
3. Invoke the ExecutionContext.setBatching(true) method to create a batch.
4. Include SQLJ executable clauses for SQL statements that you want to batch.
120
Application Programming Guide and Reference for Java
Do this so that you can control whether to commit changes to already-executed
statements when an error occurs during batch execution.
All statements that execute in a batch must use this execution context.
Subsequent batchable statements that are associated with the execution context
that you created in step 2 are added to the batch for later execution.
If you want to batch sets of statements that are not batch compatible in parallel,
you need to create an execution context for each set of batch compatible
statements.
These clauses must include the execution context that you created in step 2.
If an SQLJ executable clause has input parameters or host expressions, you can
include the statement in the batch multiple times with different values for the
input parameters or host expressions.
To determine whether a statement was added to an existing batch, was the first
statement in a new batch, or was executed inside or outside a batch, invoke the
ExecutionContext.getUpdateCount method. This method returns one of the
following values:
ExecutionContext.ADD_BATCH_COUNT
This is a constant that is returned if the statement was added to an existing
batch.
ExecutionContext.NEW_BATCH_COUNT
This is a constant that is returned if the statement was the first statement in
a new batch.
ExecutionContext.EXEC_BATCH_COUNT
This is a constant that is returned if the statement was part of a batch, and
the batch was executed.

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents