1.1 KiB
1.1 KiB
layout, title, header, resource, previoustitle, previous, nexttitle, next
layout | title | header | resource | previoustitle | previous | nexttitle | next |
---|---|---|---|---|---|---|---|
default_docs | Performing Updates | Chapter 5. Issuing a Query and Processing the Result | media | Using the ResultSet Interface | resultset.html | Creating and Modifying Database Objects | ddl.html |
To change data (perform an INSERT
, UPDATE
, or DELETE
) you use the
executeUpdate()
method. This method is similar to the method executeQuery()
used to issue a SELECT
statement, but it doesn't return a ResultSet
; instead
it returns the number of rows affected by the INSERT
, UPDATE
, or DELETE
statement. Example 5.3, “Deleting Rows in JDBC”
illustrates the usage.
Example 5.3. Deleting Rows in JDBC
This example will issue a simple DELETE
statement and print out the number of
rows deleted.
int foovalue = 500;
PreparedStatement st = conn.prepareStatement("DELETE FROM mytable WHERE columnfoo = ?");
st.setInt(1, foovalue);
int rowsDeleted = st.executeUpdate();
System.out.println(rowsDeleted + " rows deleted");
st.close();