7.5 Adding, updating, or deleting data (executing the INSERT, UPDATE, or DELETE statement)
You use the executeUpdate method or the executeLargeUpdate method of the Statement object (the PreparedStatement object if a dynamic parameter is used) to add, update, or delete data by executing a data manipulation SQL statement, such as the INSERT, UPDATE, or DELETE statement.
The following example updates and deletes 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.
-