Jdbc Executeupdate Methods Against A Db2 For Z/Os Server - IBM DB2 Manual

Table of Contents

Advertisement

Connection con;
PreparedStatement pstmt;
int numUpd;
...
pstmt = con.prepareStatement(
"UPDATE EMPLOYEE SET PHONENO=? WHERE EMPNO=?");
pstmt.setString(1,"4657");
pstmt.setString(2,"000010");
numUpd = pstmt.executeUpdate();
pstmt.setString(1,"4658");
pstmt.setString(2,"000020");
numUpd = pstmt.executeUpdate();
pstmt.close();
Figure 9. Using PreparedStatement.executeUpdate for an SQL statement with parameter
markers
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.
Connection con;
PreparedStatement pstmt;
int numUpd;
...
pstmt = con.prepareStatement(
"UPDATE EMPLOYEE SET PHONENO='4657' WHERE EMPNO='000010'");
numUpd = pstmt.executeUpdate();
pstmt.close();
Figure 10. Using PreparedStatement.executeUpdate for an SQL statement without parameter
markers
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:
// Create a PreparedStatement object
// Assign first value to first parameter
// Assign first value to second parameter
// Perform first update
// Assign second value to first parameter
// Assign second value to second parameter
// Perform second update
// Close the PreparedStatement object
// Create a PreparedStatement object
// Perform the update
// Close the PreparedStatement object 4
Chapter 3. JDBC application programming
1
2
3
4
1
3
27

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents