L ISTING 7.1
CreateTablesApp createTablesApp = new CreateTablesApp();
The section we want to focus on is listed here:
// Create the statement
Statement statement = con.createStatement();
// Use the created statement to CREATE the database table
// Create Titles Table
statement.executeUpdate(“CREATE TABLE Titles “ +
“(title_id INTEGER, title_name VARCHAR(50), “ +
“rating VARCHAR(5), price FLOAT, quantity INTEGER, “ +
“type_id INTEGER, category_id INTEGER)”);
The first statement executed creates a Statement object with the given Connection . To per-
form the actual creation of the table, call the Statement.executeUpdate() method, passing it
the SQL statement to create the table. Its signature is listed as follows:
public int executeUpdate(String sql) throws SQLException
This method is used for all update-type transactions. It takes a string representation of an SQL
statement and returns an integer. The return value is either a row count for INSERT , UPDATE , and
DELETE statements, or 0 for SQL statements that return nothing, such as a CREATE .
After you have created the Titles table, the table relationships of your Movie Catalog database
will look something like Figure 7.10.
Inserting Data into a Table
Now that you have all your tables in place, you can put some data into them. Listing 7.2 shows
the application used to populate your Movie Catalog database.