Making Batch Updates In Jdbc Applications - IBM DB2 Manual

Table of Contents

Advertisement

v For an SQL CALL statement, a value of -1 is returned, because the data source
v For any other SQL statement, a value of -1 is returned.

Making batch updates in JDBC applications

With batch updates, instead of updating rows of a table one at a time, you can
direct JDBC to execute a group of updates at the same time. Statements that can be
included in the same batch of updates are known as batchable statements.
If a statement has input parameters or host expressions, you can include that
statement only in a batch that has other instances of the same statement. This type
of batch is known as a homogeneous batch. If a statement has no input parameters,
you can include that statement in a batch only if the other statements in the batch
have no input parameters or host expressions. This type of batch is known as a
heterogeneous batch. Two statements that can be included in the same batch are
known as batch compatible.
Use the following Statement methods for creating, executing, and removing a
batch of SQL updates:
v addBatch
v executeBatch
v clearBatch
Use the following PreparedStatement and CallableStatement method for creating a
batch of parameters so that a single statement can be executed multiple times in a
batch, with a different set of parameters for each execution.
v addBatch
Restrictions on executing statements in a batch:
v If you try to execute a SELECT statement in a batch, a BatchUpdateException is
v A CallableStatement object that you execute in a batch can contain output
v You cannot retrieve ResultSet objects from a CallableStatement object that you
To make batch updates using several statements with no input parameters, follow
these basic steps:
1. For each SQL statement that you want to execute in the batch, invoke the
2. Invoke the executeBatch method to execute the batch of statements.
28
Application Programming Guide and Reference for Java
– A positive number, if a positive number of rows are affected by the operation,
and the operation is not a mass delete on a segmented table space.
– 0, if no rows are affected by the operation.
– -1, if the operation is a mass delete on a segmented table space.
cannot determine the number of affected rows. Calls to getUpdateCount or
getMoreResults for a CALL statement also return -1.
Related tasks
"Creating and modifying database objects using the Statement.executeUpdate
method" on page 24
"Updating data in tables using the PreparedStatement.executeUpdate method"
on page 25
thrown.
parameters. However, you cannot retrieve the values of the output parameters. If
you try to do so, a BatchUpdateException is thrown.
execute in a batch. A BatchUpdateException is not thrown, but the getResultSet
method invocation returns a null value.
addBatch method.

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents