Performing Updates

5.4. Performing Updates

To change data (perform an insert, update, or delete) you use the executeUpdate() method. executeUpdate() is similar to the executeQuery() used to issue a select, however it doesn't return a ResultSet, instead it returns the number of records affected by the insert, update, or delete statement.

Example 5-2. Simple Delete Example

This example will issue a simple delete and print out the number of rows deleted.

int foovalue = 500;
PreparedStatement st = db.prepareStatement("DELETE FROM mytable where columnfoo = ?");
st.setInt(1, foovalue);
int rowsDeleted = st.executeUpdate();
System.out.println(rowsDeleted + " rows deleted");
st.close();

Home
Online Resources
General
Beginner Tutorials
MySQL
PostgreSQL
Oracle
mSQL
Microsoft SQL
Contact Us
Random quote of the moment:
If our behavior is strict, we do not need fun!
 
http://www.sql.org/
 
Proudly designed and hosted by OmegaSphere, providers of all your Web Hosting, SSL Certificate, and Domain Name needs!