Java Reference
In-Depth Information
Before a Java program can connect to a database using the JDBC™ API, the
appropriate JDBC™ driver must be loaded. While the driver must be appropriate
for the type of database, and in some cases to the specific database being used,
all drivers can be loaded in the same fashion. In fact, more than one driver can
be loaded by a program. The forName() method in line 16 is used to load a
JDBC™ driver. This is a static method in the class, Class, and is used to return a
Class object associated with the given string name. Class objects represent
instances of classes (and interfaces) running in a Java application. They are con-
structed automatically by the JVM and have no public constructor. A call to
Class.forName(“X”) causes the class, X, to be loaded and initialized. Using this
method call with a database driver loads and initializes the driver class.
Because ODBC is used to connect to a Microsoft Access database, the
JDBC-ODBC Bridge driver must be loaded. The following step enters code to
load the JDBC-ODBC Bridge driver.
To Load a JDBC™ Database Driver
1. Enter line 16 as shown in Figure 11-17 on page 709.
The Class.forName() method is entered (Figure 11-19). This class method
loads and initializes the JDBC-ODBC driver.
Class.forName()
method
JDBC-ODBC
driver
FIGURE 11-19
Search WWH ::




Custom Search