Saturday, 5 July 2014

JDBC : DriverManager

🚀 Master Java database programming and backend architecture!

🔔 Subscribe to Ram N Java on YouTube

What Is the JDBC DriverManager?

In Java Database Connectivity (JDBC), the DriverManager is the foundational service layer that manages a registry of database drivers.

It sits between your Java application and the underlying vendor-specific database drivers (such as MySQL, Oracle, or SQL Server). Its primary responsibility is to inspect incoming database connection requests and route them to the appropriate driver capable of connecting to that database.

How DriverManager Selects and Establishes Connections

When your Java application initiates a database connection:

  • Driver Registration: Drivers are registered with the DriverManager (either explicitly via Class.forName("...") or automatically through modern JDBC 4.0 auto-loading).
  • URL Inspection: When DriverManager.getConnection(url, user, password) is called, the DriverManager tests each registered driver against the provided database URL.
  • Handshake & Connection: If connecting to MySQL, it selects the MySQL driver; if connecting to Oracle, it hands off to the Oracle driver, returning an active Connection instance to the application.

Key Methods in the DriverManager Class

The DriverManager class provides several utility methods to manage drivers and obtain connections:

  • getConnection(String url, String user, String password): Connects using database credentials.
  • getConnection(String url, Properties info): Connects passing connection parameters inside a Properties object.
  • registerDriver(Driver driver) / deregisterDriver(Driver driver): Manually registers or unregisters a driver instance.
  • getDrivers(): Returns an Enumeration<Driver> of all currently registered drivers.
  • getDriver(String url): Locates the specific registered driver that recognizes the given database URL.

Related Tutorials You Might Enjoy


Click here to watch in Youtube : https://www.youtube.com/watch?v=PeV1mC2z--M

Click the below Image to Enlarge
DriverManager
DriverManager
DriverManager
See also:

  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment

    Tutorials