Creating and modifying database objects using the Statement.executeUpdate method
The Statement.executeUpdate is one of the JDBC methods that you can use to update tables and call stored procedures.
About this task
You can use the Statement.executeUpdate method
to do the following things:
- Execute data definition statements, such as CREATE, ALTER, DROP, GRANT, REVOKE
- Execute INSERT, UPDATE, DELETE, and MERGE statements that do not contain parameter markers.
- 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.
Procedure
To execute these SQL statements, you need to perform these steps:
- Invoke the Connection.createStatement method to create a Statement object.
- Invoke the Statement.executeUpdate method to perform the SQL operation.
- Invoke the Statement.close method to close the Statement object.
Example
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.