Why Class.forName('database driver')?

Wednesday, July 9, 2014

Why



Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
dbConnection = DriverManager.getConnection(strUrl, props);


instead of



dbConnection = EmbeddedDriver.connect(strUrl, props);


?


Isn't it more error-prone to specify a string, instead of a class name that can be checked by the compiler? I saw an example where the class name was obtained from configuration, but this seems to be the pattern that is used regardless of available alternatives.







http://ift.tt/1mz7jdP