The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.sql  [73 examples] > Drivers  [3 examples]

e233. Loading a JDBC Driver

Before a connection to a database can be established, the JDBC driver for that database must be loaded. Drivers automatically register themselves with the JDBC system when loaded. There are two ways to load a JDBC driver. The first is to specify the driver or colon-separated list of drivers on the command line:
    > java -Djdbc.drivers=com.company1.Driver:com.company2.Driver MyApp

The second, and recommended method, is to call Class.forName() within the code:
    try {
        // Load the JDBC driver
        String driverName = "org.gjt.mm.mysql.Driver";
        Class.forName(driverName);
    } catch (ClassNotFoundException e) {
        // Could not find the driver
    }

 Related Examples
e232. Getting JDBC Drivers for a Database
e234. Listing All Loaded JDBC Drivers

See also: Batching    Connections    Database Meta Data    Deleting Data    Importing and Exporting    Inserting and Updating Data    Oracle OBJECTs    Oracle VARRAYs    Procedures and Functions    Retrieving Data    Scrollable Result Sets    Tables    Updatable Result Sets   


© 2002 Addison-Wesley.