Java Reference
In-Depth Information
Use of the DELETE command is very straightforward. For example, this is the command you use to
delete records containing the First_Name: "Michael" and the Last_Name: "Corleone":
DELETE FROM Contact_Info
WHERE First_Name = 'Michael' AND Last_Name = 'Corleone';
Caution
INSERT, DELETE, and UPDATE can cause referential integrity problems with other
tables, as well as significant problems within the table you are working on. Delete with
care.
A Swing-Based Table Editor
To illustrate the topics covered in this chapter, the Swing-based table builder created in Chapter 5 is
extended by the addition of a table editor (see Figure 6-1 ) . The table editor is based on components
derived from components built in Chapter 5 . A new Edit menu (with Insert, Update, Delete,
JMenuItems ) and a new JTable in a JInternalFrame (for handling the Insert, Edit, and Delete
functions) are also added.
Figure 6-1: Inserting data with SQL INSERT
The events are as follows:
1. The user selects a database.
2. The user selects an action: Insert, Update, or Delete.
3. The user selects the table.
4. A TableEdit frame is displayed for user interaction.
5. A SQL command is created dynamically and executed on command.
The first step in building the table editor is to create the Edit menu by subclassing the DBMenu
convenience class. The DBMenuItems Insert, Update, and Delete to the Edit menu are added and
hooked into the Jframe, which forms the basis of the MainFrame class.
Listing 6-4: Edit menu with insert, update, and delete items
Search WWH ::




Custom Search