Skip to content

Most visited

Recently visited

navigation
Added in API level 1

DriverManager

public class DriverManager
extends Object

java.lang.Object
   ↳ java.sql.DriverManager


Provides facilities for managing JDBC drivers. The android.database and android.database.sqlite packages offer a higher-performance alternative for new code.

Note that Android does not include any JDBC drivers by default; you must provide your own.

The DriverManager class loads JDBC drivers during its initialization, from the list of drivers referenced by the system property "jdbc.drivers".

Summary

Public methods

static void deregisterDriver(Driver driver)

Removes a driver from the DriverManager's registered driver list.

static Connection getConnection(String url, Properties info)

Attempts to establish a connection to the given database URL.

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

Attempts to establish a connection to the given database URL.

static Connection getConnection(String url)

Attempts to establish a connection to the given database URL.

static Driver getDriver(String url)

Tries to find a driver that can interpret the supplied URL.

static Enumeration<Driver> getDrivers()

Returns an Enumeration that contains all of the loaded JDBC drivers that the current caller can access.

static PrintStream getLogStream()

This method was deprecated in API level 1. Use getLogWriter() instead.

static PrintWriter getLogWriter()

Retrieves the log writer.

static int getLoginTimeout()

Returns the login timeout when connecting to a database in seconds.

static void println(String message)

Prints a message to the current JDBC log stream.

static void registerDriver(Driver driver)

Registers a given JDBC driver with the DriverManager.

static void setLogStream(PrintStream out)

This method was deprecated in API level 1. Use setLogWriter(PrintWriter) instead.

static void setLogWriter(PrintWriter out)

Sets the PrintWriter that is used by all loaded drivers, and also the DriverManager.

static void setLoginTimeout(int seconds)

Sets the login timeout when connecting to a database in seconds.

Inherited methods

From class java.lang.Object

Public methods

deregisterDriver

Added in API level 1
void deregisterDriver (Driver driver)

Removes a driver from the DriverManager's registered driver list. This will only succeed when the caller's class loader loaded the driver that is to be removed. If the driver was loaded by a different class loader, the removal of the driver fails silently.

If the removal succeeds, the DriverManager will not use this driver in the future when asked to get a Connection.

Parameters
driver Driver: the JDBC driver to remove.
Throws
SQLException if there is a problem interfering with accessing the database.

getConnection

Added in API level 1
Connection getConnection (String url, 
                Properties info)

Attempts to establish a connection to the given database URL.

Parameters
url String: a URL string representing the database target to connect with
info Properties: a set of properties to use as arguments to set up the connection. Properties are arbitrary string/value pairs. Normally, at least the properties "user" and "password" should be passed, with appropriate settings for the user ID and its corresponding password to get access to the corresponding database.
Returns
Connection a Connection to the database identified by the URL. null if no connection can be established.
Throws
SQLException if there is an error while attempting to connect to the database identified by the URL.

getConnection

Added in API level 1
Connection getConnection (String url, 
                String user, 
                String password)

Attempts to establish a connection to the given database URL.

Parameters
url String: a URL string representing the database target to connect with.
user String: a user ID used to login to the database.
password String: a password for the user ID to login to the database.
Returns
Connection a Connection to the database identified by the URL. null if no connection can be established.
Throws
SQLException if there is an error while attempting to connect to the database identified by the URL.

getConnection

Added in API level 1
Connection getConnection (String url)

Attempts to establish a connection to the given database URL.

Parameters
url String: a URL string representing the database target to connect with.
Returns
Connection a Connection to the database identified by the URL. null if no connection can be established.
Throws
SQLException if there is an error while attempting to connect to the database identified by the URL.

getDriver

Added in API level 1
Driver getDriver (String url)

Tries to find a driver that can interpret the supplied URL.

Parameters
url String: the URL of a database.
Returns
Driver a Driver that matches the provided URL. null if no Driver understands the URL
Throws
SQLException if there is any kind of problem accessing the database.

getDrivers

Added in API level 1
Enumeration<Driver> getDrivers ()

Returns an Enumeration that contains all of the loaded JDBC drivers that the current caller can access.

Returns
Enumeration<Driver> An Enumeration containing all the currently loaded JDBC Drivers.

getLogStream

Added in API level 1
PrintStream getLogStream ()

This method was deprecated in API level 1.
Use getLogWriter() instead.

Gets the log PrintStream used by the DriverManager and all the JDBC Drivers.

Returns
PrintStream the PrintStream used for logging activities.

getLogWriter

Added in API level 1
PrintWriter getLogWriter ()

Retrieves the log writer.

Returns
PrintWriter A PrintWriter object used as the log writer. null if no log writer is set.

getLoginTimeout

Added in API level 1
int getLoginTimeout ()

Returns the login timeout when connecting to a database in seconds.

Returns
int the login timeout in seconds.

println

Added in API level 1
void println (String message)

Prints a message to the current JDBC log stream. This is either the PrintWriter or (deprecated) the PrintStream, if set.

Parameters
message String: the message to print to the JDBC log stream.

registerDriver

Added in API level 1
void registerDriver (Driver driver)

Registers a given JDBC driver with the DriverManager.

A newly loaded JDBC driver class should register itself with the DriverManager by calling this method.

Parameters
driver Driver: the Driver to register with the DriverManager.
Throws
SQLException if a database access error occurs.

setLogStream

Added in API level 1
void setLogStream (PrintStream out)

This method was deprecated in API level 1.
Use setLogWriter(PrintWriter) instead.

Sets the print stream to use for logging data from the DriverManager and the JDBC drivers.

Parameters
out PrintStream: the PrintStream to use for logging.

setLogWriter

Added in API level 1
void setLogWriter (PrintWriter out)

Sets the PrintWriter that is used by all loaded drivers, and also the DriverManager.

Parameters
out PrintWriter: the PrintWriter to be used.

setLoginTimeout

Added in API level 1
void setLoginTimeout (int seconds)

Sets the login timeout when connecting to a database in seconds.

Parameters
seconds int: seconds until timeout. 0 indicates wait forever.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.