Java Reference
In-Depth Information
MI CHAR(1) NULL,
LAST_NAME VARCHAR(30) NOT NULL,
STREET VARCHAR(50) NOT NULL,
CITY VARCHAR(30) NOT NULL,
STATE CHAR(2) NOT NULL,
ZIP VARCHAR(10) NOT NULL);
Caution
Notice the semicolon terminating the command. Most dialects of SQL work with
semicolons, but some, such as Transact-SQL, require the keyword GO. We use
semicolons in our examples.
The next section will show you how to use the SQL CREATE TABLE from a Java application.
Creating a Table Using JDBC
The JDBC API is made up of a small number of important classes and interfaces that handle the tasks
of loading a suitable driver for your database, connecting to the database, creating and executing a
SQL command, and handling any returned records. The primary classes we use for this example are
as follows:
 
DriverManager
 
Driver
 
Connection
 
Statement
DriverManager
The DriverManager is responsible for loading JDBC drivers and for returning a connection to the
appropriate driver. The DriverManager locates a suitable driver for the URL provided in the
getConnection() call by polling the registered drivers.
Driver
For the examples in this topic, we use the JDBC ODBC bridge. The first thing we do is load the
sun.jdbc.odbc.JdbcOdbcDriver by name, using Class.forName() .Then we register it with
the DriverManager, using this command:
DriverManager.registerDriver(new JdbcOdbcDriver());
Connection
We next request a connection to the database from the DriverManager using the following command:
getConnection(jdbc:driverName:databaseName);
Search WWH ::




Custom Search