DriverManager class

The DriverManager class belongs to the java.sql package and is responsible for managing JDBC drivers. It acts as an important component between a Java application and the JDBC drivers. The DriverManager selects an appropriate JDBC driver based on the database URL provided by the application. It is mainly used to establish a connection with a database using the getConnection() method. It also provides methods for registering, deregistering, and retrieving JDBC drivers.

Methods of DriverManager

Method Signature and Short Description

public static Connection getConnection(String url)

Establishes a connection to the database using the specified JDBC URL.

public static Connection getConnection(String url, String user, String password)

Establishes a database connection using the specified URL, username, and password.

public static Connection getConnection(String url, Properties info)

Establishes a database connection using the specified URL and connection properties.

public static void registerDriver(Driver driver)

Registers the specified JDBC driver with the DriverManager.

public static void deregisterDriver(Driver driver)

Removes the specified JDBC driver from the registered drivers.

public static Driver getDriver(String url)

Locates and returns a JDBC driver that understands the specified database URL.

public static Enumeration<Driver> getDrivers()

Returns all JDBC drivers currently registered with the DriverManager.

public static void setLoginTimeout(int seconds)

Sets the maximum time allowed for establishing a database connection.

public static int getLoginTimeout()

Returns the maximum time allowed for establishing a database connection.

public static void setLogWriter(PrintWriter out)

Sets the output destination for JDBC driver logging and tracing.

public static PrintWriter getLogWriter()

Returns the current logging and tracing output destination.

public static void println(String message)

Prints the specified message to the DriverManager log writer.

Scroll to Top