The only reason to do the Class.forName() is for the side effect of causing the class definition to be loaded. The actual Class instance, as Ulf pointed out, is not required at any point.
Originally posted by Prad Dip: Just FYI. In Java 6 we would no longer be needing class.forName. Just put the vendor jar in classpath, the JDK will load the driver class.
Can you explain how this should work, since it doesn't work for me.
Elaborating: I connect to MSSQL 2005 using a correct connection string: jdbc:sqlserver://<host>;DatabaseName=<database> (using the default port 1433)
When I use this in DriverManager.getConnection without loading the class it fails, stating it can't find the driver. If I do load the class manually, no problems.
The JAR file is in my <JRE home>\lib\ext folder, but it also doesn't work when specified on the classpath.
So, what's the magic I'm forgetting? [ January 03, 2008: Message edited by: Rob Prime ]