EasyManuals Logo

IBM DB2 User Manual

IBM DB2
585 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #41 background imageLoading...
Page #41 background image
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

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM DB2 and is the answer not in the manual?

IBM DB2 Specifications

General IconGeneral
DeveloperIBM
Initial Release1983
LicenseProprietary
Written inC, C++
CategoryDatabase Management System (RDBMS)
Operating SystemLinux, Windows
Programming LanguagesC, C++
Data ModelsRelational
EditionsCommunity, Standard, Advanced
Key Featureshigh availability, scalability