7.5 When adding, updating, or deleting data (executing INSERT, UPDATE, or DELETE statements), or executing a COPY statement
In the following cases, use the executeUpdate method or the executeLargeUpdate method of the Statement object (the PreparedStatement object if a dynamic parameter is used):
-
When adding, updating, or deleting data by using update SQL statements such as INSERT, UPDATE, or DELETE statements
-
When executing COPY statements
The following shows an example of updating and deleting data.
Connection con = DriverManager.getConnection(url, info);
Statement stmt = con.createStatement();
// Update the data that satisfies the condition
stmt.executeUpdate("UPDATE \"SAMPLE\" SET \"CODE\"=98765 WHERE \"STATE\" = 'Redmond'");
// Delete all rows
stmt.executeUpdate("DELETE FROM \"SAMPLE\" ");
- ■ Effects of update operations on a retrieval using a cursor
-
If an update operation using a cursor is performed during a retrieval, the results of the update operation might be applied to the retrieval results, depending on the timing. Do the following to prevent the results of such update operations from being applied to retrieval results:
-
Close the cursor before adding or updating rows.
-
Specify data and search conditions in such a manner that rows to be added or updated will not be included in the retrieval results.
-