Java Reference
In-Depth Information
TABLEMODIFIER.EXECUTE(SQLALTER);
}
}
From time to time, you may need to delete a table. Deleting tables, like creating and altering tables, is
easy to do using SQL and JDBC.
Deleting or Dropping a Table
Deleting a table with SQL is done using the DROP TABLE command. The DROP TABLE command
deletes a table along with all its associated views and indexes. Here's the syntax for the DROP TABLE
command:
DROP TABLE table_name;
To drop the CONTACT_INFO , issue this command:
DROP TABLE CONTACT_INFO;
Since the code used to drop a table is very similar to the code used to create or alter a table, a
dedicated Java example for DROP TABLE , is not provided. The Table Builder example discussed in the
next section includes an example of the code required to drop a table in listing 5-3 .
Creating a Swing-based Table Builder
To illustrate the topics covered in this chapter, we build a Swing-based Table Builder. This application
forms the basis of a complete database management console, which, with only minor modifications,
works with any database management system.
The Table Builder uses Model View Controller (MVC) architecture, both for clarity, and because MVC
designs are easier to understand, build, and maintain. The first step is to create the controller portion of
the MVC architecture.
The controller responds to user inputs from the various view elements and commands the model to
execute the user's commands. User inputs come from JMenus, dialog boxes, and JInternalFrames.
The sequence of events is as follows:
1. User selects a database.
2. User assigns a table name.
3. User defines the required fields for the table.
4. SQL CREATE TABLE command is issued to create the desired table.
The controller interacts with the model using classes based on the code we look at in Listing 5-1 .
The view portion of the MVC architecture is handled by the usual JMenu items, together with a
JOptionPane to deal with single-value inputs such as database name and table name, and dedicated
JInternalFrames to handle anything more complicated. The view components interact with the
controller only for initialization and to return the data they are designed to collect. The model portion of
Search WWH ::




Custom Search