Java Reference
In-Depth Information
Creating a Table
The first thing you will do is create a database table that represents a list of movie titles.
Currently two tables are in the database: the Categories table and the Types table. Table 7.1
shows the composition of your new Titles table.
T ABLE 7.1 Titles Table Elements
Field Name
Data Type
title_id
INTEGER
7
title_name
VARCHAR(50)
rating
VARCHAR(5)
price
FLOAT
quantity
INTEGER
type_id
INTEGER
category_id
INTEGER
The application that creates this table can be found in Listing 7.1. Notice that it follows the
step-by-step process that I described earlier:
1.
Open a connection to the database.
2.
Execute a SQL statement.
3.
Process the results.
4.
Close the connection to the database.
L ISTING 7.1
CreateTablesApp.java
import java.sql.*;
public class CreateTablesApp {
public void createTables() {
Connection con = null;
try {
// Load the Driver class file
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
// Make a connection to the ODBC datasource Movie Catalog
 
Search WWH ::




Custom Search