Java Reference
In-Depth Information
Other setup work might be needed depending on the ODBC drivers present on your sys-
tem, if any. Consult the documentation included with the ODBC driver.
After you have downloaded
world20.mdb
to your computer or found another database
that's compatible with the ODBC drivers on your system, the final step in getting the file
ready for JDBC-ODBC is to create a data source associated with it. Unlike other input-
output classes in Java, JDBC doesn't use a filename to identify a data file and use its
contents. Instead, a tool such as the ODBC Data Source Administrator is used to name
the ODBC source and indicate the file folder where it can be found.
In the ODBC Data Source Administrator, click the User DSN tab to see a list of data
sources that are available. To add a new one associated with
world20.mdb
(or your own
database), click the Add button, choose an ODBC driver, and then click the Finish
button.
A Setup window opens that you can use to provide a name, short description, and other
information about the database. Click the Select button to find and choose the database
file.
Figure 18.3 shows the Setup window used to set up
world20.mdb
as a data source in the
ODBC Data Source Administrator.
FIGURE 18.3
The ODBC driver
Setup window.
After a database has been associated with an ODBC data source, working with it in a
Java program is relatively easy if you are conversant with SQL.
The first task in a JDBC program is to load the driver (or drivers) that will be used to
connect to a data source. A driver is loaded with the
Class.forName(
String
)
method.
Class
, part of the
java.lang
package, can be used to load classes into the Java inter-
preter. The
forName(
String
)
method loads the class named by the specified string. A
ClassNotFoundException
can be thrown by this method.