public class DriverManager extends Object
The DriverManager manages JDBC drivers and database connection requests. Although the drivers can be registered and loaded with the class.forName() method, the DriverManager uses the jdbc.drivers property during its initialization phase to find a suitable driver for the connection that is requested.
See also: Driver, Connection
deregisterDriver
public static void deregisterDriver(Driver driver) throws SQLException
This removes a Driver from the DriverManager’s list. In the case of applets, only Drivers from the applet’s own classloader can be deregistered.
Parameters:
driver: | A JDBC Driver |
getConnection
public static synchronized Connection getConnection(String url, Properties info) throws SQLException
getConnection() returns a Connection object if the DriverManager is able to find an appropriate driver for the requested connection.
Parameters:
url: | A database URL |
info: | A list of string tag/value pairs as connection arguments |
Returns: A Connection to the database URL
getConnection
public static synchronized Connection getConnection(String url, String user, String password) throws SQLException
getConnection() returns a Connection object if the DriverManager is able to find an appropriate driver for the requested connection.
Parameters:
url: | A database URL |
user: | A database user’s login |
password: | The user’s password |
Returns: A Connection to the database URL
getConnection
public static synchronized Connection getConnection(String url) throws SQLException
getConnection() returns a Connection object if the DriverManager is able to find an appropriate driver for the requested connection.
Parameters:
url: | A database URL usually containing user and password strings |
Returns: A Connection to the database URL
getDriver
public static Driver getDriver(String url) throws SQLException
This method is used to locate a Driver that is able to connect to the database URL. The Driver is selected from the set of registered Drivers.
Parameters:
url: | A database URL |
Returns: A Driver able to connect to the URL
getDrivers
public static Enumeration getDrivers()
This gets an Enumeration of the JDBC drivers that are currently loaded.
Returns: The list of JDBC drivers that are loaded
getLoginTimeout
public static int getLoginTimeout()
This gets the maximum time in seconds that all drivers can wait when attempting to log in to a database.
Returns: The login time limit
getLogStream
public static PrintStream getLogStream()
The DriverManager and JDBC drivers can give detailed information on what they do during a connection. This method returns the PrintStream used by the DriverManager and the drivers.
Returns: The logging/tracing PrintStream or null if logging/tracing is disabled
getLogWriter
public static java.io.PrintWriter getLogWriter()
The DriverManager and JDBC drivers can give detailed information on what they do during a connection. This method returns the PrintWriter used by the DriverManager and the drivers.
Returns: The java.io.PrintWriter object
println
public static void println(Stringmessage)
This prints a string to the current JDBC log stream.
Parameters:
message: | A log message |
registerDriver
public static synchronized void registerDriver(Driverdriver) throws SQLException
JDBC drivers must register themselves with the DriverManager in order to be candidates for subsequent connections.
Parameters:
driver: | A JDBC Driver |
setLoginTimeout
public static void setLoginTimeout(int seconds)
This sets the maximum time in seconds that all drivers can wait when attempting to log in to a database.
Parameters:
seconds: | The login time limit |
setLogStream
public static void setLogStream(PrintStream out)
The DriverManager and JDBC drivers can give detailed information on what they do during a connection. This method sets the PrintStream used by the DriverManager and the drivers.
Parameters:
out: | The logging/tracing PrintStream or null to disable the logging/tracing facility |
setLogWriter
public static void setLogWriter(PrintWriter out)
The DriverManager and JDBC drivers can give detailed information on what they do during a connection. This method sets the PrintWriter used by the DriverManager and the drivers. If a SecurityManager exists and its checkPermission method denies setLog, this method throws a SecurityException.
Parameters:
out: | The logging/tracing PrintWriter or null to disable the logging/tracing facility |