I understand that this is better for a dynamic decision between multiple drivers maybe read from an XML config file or user input. The thing I am curious about is how does invoking this statement loads the stated driver into the environment where we are not even storing the resultant "Class" object anywhere. The JavaDocs entry says:

Note that there exist buggy JDBC drivers such as org.gjt.mm.mysql.Driver which incorrectly registers itself inside the constructor instead. That's why you need a newInstance() call afterwards on such drivers to get them to register themselves.

@BalusC, Why do we need to use Class.forName to run the static initializer? If we use SomeDriver directly, e.g. if we have already an instance of it, or we call SomeDriver.StaticMethod directly, then wouldn't that already ensured that the static initializer will be called?
–
PacerierAug 24 '14 at 22:24

1

@Pacerier: Because you don't want to have a dependency on SomeDriver (i.e. you don't want to import it anywhere in your code). This way your code is portable across various JDBC drivers without the need to change it everytime you (or enduser!) switch driver or DB. Related: stackoverflow.com/q/7550612
–
BalusCAug 25 '14 at 5:30

@BalusC, I mean if somewhere in the code, it already did SomeDriver.StaticMethod, or new SomeDriver or some_driver.Method, then why do we need to use Class.forName to run the static initializer?
–
PacerierAug 25 '14 at 5:44