Modifying a database is just as
simple as querying a database. However, instead of using
executeQuery(), you use executeUpdate() and you don't have
to worry about a result set. Consider the following example:
Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);
Connection jdbcConnection =
DriverManager.getConnection
(jdbc:odbc:Access);
Statement sqlStatement = jdbcConnection.createStatement();
// We have seen all of the above before.
// No surprises so far. in the next line, we
// will simply create a string of SQL.
String sql = "INSERT INTO CUSTOMERS +
" (CustomerID, Firstname, LastName, Email)" +
" VALUES (004, 'Selena', 'Sol' " +
"'selena@extropia.com')";
// Now submit the SQL....
sqlStatement.executeUpdate(sql);
As you can see, there is not much to it.
Add, modify and delete are all handled by the
executeUpdate() method. You compose the SQL and send it
through JDBC in one simple call.