In order to update the database you need to use a Statement. But, instead of calling theexecuteQuery() method, you call the executeUpdate() method.
There are two types of updates you can perform on a database:
  1. Update record values
  2. Delete records
The executeUpdate() method is used for both of these types of updates.

Updating Records

Here is an update record value example:
Statement statement = connection.createStatement();

String    sql       = "update people set name='John' where id=123";

int rowsAffected    = statement.executeUpdate(sql);
The rowsAffected returned by the statement.executeUpdate(sql) call, tells how many records in the database were affected by the SQL statement.

Deleting Records

Here is a delete record example:
Statement statement = connection.createStatement();

String    sql       = "delete from people where id=123";

int rowsAffected    = statement.executeUpdate(sql);
Again, the rowsAffected returned by the statement.executeUpdate(sql) call, tells how many records in the database were affected by the SQL statement.

Powered by Blogger.

- Copyright © 2013 Taqi Shah Blogspot -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -