You can also use the PreparedStatement.executeUpdate method for statements that
have no parameter markers. The steps for executing a PreparedStatement object
with no parameter markers are similar to executing a PreparedStatement object
with parameter markers, except you skip step 2 on page 26. The following example
demonstrates these steps.
Related concepts
“JDBC interfaces for executing SQL” on page 24
“JDBC executeUpdate methods against a DB2 for z/OS server”
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
JDBC executeUpdate methods against a DB2 for z/OS server
The JDBC standard states that the executeUpdate method returns a row count or 0.
However, if the executeUpdate method is executed against a DB2 for z/OS server,
it can return a value of -1.
For executeUpdate statements against a DB2 for z/OS server, the value that is
returned depends on the type of SQL statement that is being executed:
v For an SQL statement that can have an update count, such as an INSERT,
UPDATE, or DELETE statement, the returned value is the number of affected
rows. It can be:
Connection con;
PreparedStatement pstmt;
int numUpd;
...
pstmt = con.prepareStatement(
"UPDATE EMPLOYEE SET PHONENO=? WHERE EMPNO=?");
// Create a PreparedStatement object 1
pstmt.setString(1,"4657"); // Assign first value to first parameter 2
pstmt.setString(2,"000010"); // Assign first value to second parameter
numUpd = pstmt.executeUpdate(); // Perform first update 3
pstmt.setString(1,"4658"); // Assign second value to first parameter
pstmt.setString(2,"000020"); // Assign second value to second parameter
numUpd = pstmt.executeUpdate(); // Perform second update
pstmt.close(); // Close the PreparedStatement object 4
Figure 9. Using PreparedStatement.executeUpdate for an SQL statement with parameter
markers
Connection con;
PreparedStatement pstmt;
int numUpd;
...
pstmt = con.prepareStatement(
"UPDATE EMPLOYEE SET PHONENO='4657' WHERE EMPNO='000010'");
// Create a PreparedStatement object 1
numUpd = pstmt.executeUpdate(); // Perform the update 3
pstmt.close(); // Close the PreparedStatement object 4
Figure 10. Using PreparedStatement.executeUpdate for an SQL statement without parameter
markers
Chapter 3. JDBC application programming 27