How does DriverManager identify the type of driver loaded into JVM

Typical JDBC code to connect to the database is:

* Responsible for loading the class into
* into JVM at runtime
* DriverManager getting the connection object
* based on the driver loaded above
Connection con=DriverManager.getConnection(url);</code></div>

QUESTION is who will instantiate the class that is loaded and who will register that class with DM? It is done through the static block of code in the class which will instantiate itself and register with DriverManager

Here is the source from MySQL

public class Driver extends NonRegisteringDriver implements java.sql.Driver {
// Register ourselves with the DriverManager
static {
try {
java.sql.DriverManager.registerDriver(new Driver());
} catch (SQLException E) {
throw new RuntimeException("Can't register driver!");
* Construct a new driver and register it with DriverManager
* @throws SQLException
*             if a database error occurs.
public Driver() throws SQLException {
// Required for Class.forName().newInstance()

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s