Class.forName() explicitly loads the driver class. DriverManager.registerDriver() should be called automatically by the driver when it's loaded. It registers the driver with the DriverManager. The recommended way is the first one.
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Originally posted by daya mukiri: Hi Bosun, can you explain that some what deeply? does drivermanager internally uses class.forname to load the driver?
No. In Java, classes are almost always loaded implicitly, when they're referenced, and not before. When DriverManager.registerDriver(new aJDBCDriver()); is called, "new aJDBCDriver()" loads the driver (and if the driver conforms to the JDBC specification, loading the driver causes it to call DriverManager.registerDriver() upon itself!! ).
Explicitly loading a class with class.forname is a very rare thing, used to select a class at run time, instead of at compile time. It is used in JDBC so that people can write code that will work with any database driver.