July 28, 2022

JDBC DriverManager Class

java.sql.DriverManager class in JDBC API in Java is a utility class to manage a set of JDBC drivers. Before connection to DB and start any DB operation you will have to register the driver for that specific DB with the DriverManager class.

Java DriverManager class methods

Main task of the DriverManager class is to register JDBC driver and to establish a connection with the DB for these tasks following methods are provided in the DriverManager class-

  • registerDriver(Driver driver)- Registers the given driver with the DriverManager.
  • registerDriver(Driver driver, DriverAction da)- Registers the given driver with the DriverManager. Using DriverAction you can specify an implementation that has to be called when deregisterDriver() method of DriverManager is called.
  • deregisterDriver(Driver driver)- Removes the specified driver from the DriverManager's list of registered drivers.
  • getDriver(String url) -Attempts to locate a driver that understands the given URL.
  • getDrivers()- Returns an Enumeration with all of the currently loaded JDBC drivers.
  • getLoginTimeout()- Gets the maximum time in seconds that a driver can wait when attempting to log in to a database.
  • getConnection(String url)- Attempts to establish a connection to the given database URL.
  • getConnection(String url, String user, String password)- Attempts to establish a connection to the given database URL, passing the DB credentials; user and password as other arguments.
  • getConnection(String url, Properties info)- Attempts to establish a connection to the given database URL, passing a list of arbitrary string tag/value pairs as connection arguments.

That's all for the topic JDBC DriverManager Class . If something is missing or you have something to share about the topic please write a comment.


You may also like

No comments:

Post a Comment