This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
When the method getConnection is called, the DriverManager will attempt to locate a suitable driver from amongst those loaded at initialization and those loaded explicitly using the same classloader as the current applet or application.
the Class.forname() simply registers the driver with
When calling DriverManager.getConnection() the
implementation iterates over all registered drivers
and tries to connect.
If an Exception is thrown, it continues iterating.
You can have a look in the DriverManager.java
Your Java installation comes with src.zip that includes
all source code.
The key is the connection URL passed to the DriverManager.getConnection() or getDriver() methods. Compare the URLs for several different database's JDBC drivers and you will see that even though they all start with "jdbc:", after that they are quite different, with the next word usually identifying the database type. The Driver Manager, when given the connection URL, cycles through the registered JDBC drivers asking each one whether it recognizes the URL. The first driver to say this it does is the one used.