v Execute INSERT, UPDATE, DELETE, and MERGE statements that do not contain
parameter markers.
v With the IBM Data Server Driver for JDBC and SQLJ, execute the CALL
statement to call stored procedures that have no parameters and that return no
result sets.
To execute these SQL statements, you need to perform these steps:
1. Invoke the Connection.createStatement method to create a Statement object.
2. Invoke the Statement.executeUpdate method to perform the SQL operation.
3. Invoke the Statement.close method to close the Statement object.
Suppose that you want to execute this SQL statement:
UPDATE EMPLOYEE SET PHONENO='4657' WHERE EMPNO='000010'
The following code creates Statement object stmt, executes the UPDATE statement,
and returns the number of rows that were updated in numUpd. The numbers to the
right of selected statements correspond to the previously-described steps.
Related concepts
“JDBC interfaces for executing SQL” on page 24
“JDBC executeUpdate methods against a DB2 for z/OS server” on page 27
Related tasks
“Retrieving automatically generated keys in JDBC applications” on page 58
Related reference
“Driver support for JDBC APIs” on page 252
“JDBC differences between the current IBM Data Server Driver for JDBC and
SQLJ and earlier DB2 JDBC drivers” on page 370
Updating data in tables using the
PreparedStatement.executeUpdate method
The Statement.executeUpdate method works if you update DB2 tables with
constant values. However, updates often need to involve passing values in
variables to DB2 tables. To do that, you use the PreparedStatement.executeUpdate
method.
With the IBM Data Server Driver for JDBC and SQLJ, you can also use
PreparedStatement.executeUpdate to call stored procedures that have input
parameters and no output parameters, and that return no result sets.
Connection con;
Statement stmt;
int numUpd;
...
stmt = con.createStatement(); // Create a Statement object 1
numUpd = stmt.executeUpdate(
"UPDATE EMPLOYEE SET PHONENO='4657' WHERE EMPNO='000010'"); 2
// Perform the update
stmt.close(); // Close Statement object 3
Figure 8. Using Statement.executeUpdate
Chapter 3. JDBC application programming 25