Why Class.forName('database driver')?

Wednesday, July 9, 2014


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.