Inserting, Updating, and Deleting Data

After you know the SQL commands, it's not hard to make database updates. The pattern for performing inserts, updates, and deletions is basically the same. You can either use the Statement or the PreparedStatement interface, depending on whether you want to insert the data into the SQL string or use parameterized data.

Listing 3.2 shows a program that inserts, updates, and then deletes a row. The example uses the original definition of the Person table from Chapter 2, "A Quick Primer on SQL."

Code Listing 3.2. Source Code for InsUpdDel.java
 package usingj2ee.jdbc; import java.sql.*; public class InsUpdDel { public static void main(String[] args) { try { // Make sure the DriverManager knows about the driver ...

Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.