DriverManager class in JDBC | Java JDBC Tutorial

This Java JDBC Tutorial “DriverManager class in JDBC” post is providing the importance of DriverManager class in JDBC application development and it is providing all the available methods in DriverManager class.


 

DriverManager Class:

public class DriverManager extends Object

 

  • The basic service for managing a set of JDBC drivers.
  • The JDBC Driver Manager is a very important class that defines objects which connect Java applications to a JDBC driver.
  • The main responsibility of JDBC database driver is to load all the drivers found in the system properly as well as to select the most appropriate driver from opening a connection to a database.
  • The Driver Manager also helps to select the most appropriate driver from the previously loaded drivers when a new open database is connected.
  • This class is mainly useful for the simple application, the most frequently used method of this class is DriverManager.getConnetion(). We can know by the name of the method that this method establishes a connection to a database.
  • The DriverManager class maintains the list of the Driver classes. Each driver has to be get registered in the DriverManager class by calling the method DriverManager.registerDriver().
  • The driver is loaded by calling the Class.forName() method.

 

DriverManager class Methods:

  1. deregisterDriver(Driver driver) : It drops the driver from the list of drivers registered in the DriverManager class.
  2. registerDriver(Driver driver) : It registers the driver with the DriverManager class.
  3. getConnection(String url) : It tries to establish the connection to a given database URL.
  4. getConnection(String url, Sting user, String password) : It tries to establish the connection to a given database URL.
  5. getConnection(String url, Properties info) : It tries to establish the connection to a given database URL.
  6. getDriver(String url) : It attempts to locate the driver by the given string.
  7. getDrivers() : It retrieves the enumeration of the drivers which has been registered with the DriverManager class.
Share this