// sample code from MM.MySql documentation // -- source: http://www.worldserver.com/mm.mysql/doc/mm.doc/book1.htm // -- modifications: slight formatting modifications // + short additions from other sources // + moving code to load the MM.MySql JDBC driver // to the static load() method so it can be called from // other classes // need to set the CLASSPATH to .\;C:\...\mm.mysql.jdbc-1.2b // Example 3-1. Registering the Driver with the DriverManager import java.sql.*; // Notice, do not import org.gjt.mm.mysql.* // or you will have problems! public class LoadDriver { // load the MM.MySql JDBC driver (register it with the // driver manager public static boolean load() { try { // The newInstance() call is a work around for some // broken Java implementations Class.forName("org.gjt.mm.mysql.Driver").newInstance(); return true; // we loaded the driver! } catch (Exception e) { System.err.println("Unable to load driver."); e.printStackTrace(); return false; // we didn't load the driver! } } // load() public static void main(String[] Args) { boolean isDriverLoaded = false; // load the MM.MySQL JDBC driver isDriverLoaded = load(); // the remaining code from Henri Jubin text with // slight modifications and additions of remarks if (isDriverLoaded) { System.out.println("JDBC driver loaded"); System.out.println(); // get a list of the loaded drivers java.util.Enumeration enum = DriverManager.getDrivers(); // print out the loaded JDBC drivers System.out.println("Loaded drivers are:"); while( enum.hasMoreElements()) { System.out.println(enum.nextElement()); } // while } // if } // main() } // class LoadDriver