java.sql
Class DriverManager
This class manages the JDBC drivers in the system. It maintains a
registry of drivers and locates the appropriate driver to handle a
JDBC database URL.
On startup,
DriverManager
loads all the managers specified
by the system property
jdbc.drivers
. The value of this
property should be a colon separated list of fully qualified driver
class names. Additional drivers can be loaded at any time by
simply loading the driver class with
class.forName(String)
.
The driver should automatically register itself in a static
initializer.
The methods in this class are all
static
. This class
cannot be instantiated.
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
deregisterDriver
public static void deregisterDriver(Driver driver)
throws SQLException
This method de-registers a driver from the manager.
driver
- The Driver
to unregister.
getConnection
public static Connection getConnection(String url)
throws SQLException
This method attempts to return a connection to the specified
JDBC URL string.
url
- The JDBC URL string to connect to.
- A
Connection
to that URL.
getConnection
public static Connection getConnection(String url,
String user,
String password)
throws SQLException
This method attempts to return a connection to the specified
JDBC URL string using the specified username and password.
url
- The JDBC URL string to connect to.user
- The username to connect with.password
- The password to connect with.
- A
Connection
to that URL.
getConnection
public static Connection getConnection(String url,
Properties properties)
throws SQLException
This method attempts to return a connection to the specified
JDBC URL string using the specified connection properties.
url
- The JDBC URL string to connect to.properties
- The connection properties.
- A
Connection
to that URL.
getDriver
public static Driver getDriver(String url)
throws SQLException
This method returns a driver that can connect to the specified
JDBC URL string. This will be selected from among drivers loaded
at initialization time and those drivers manually loaded by the
same class loader as the caller.
url
- The JDBC URL string to find a driver for.
- A
Driver
that can connect to the specified
URL.
SQLException
- If an error occurs, or no suitable driver can be found.
getDrivers
public static Enumeration getDrivers()
This method returns a list of all the currently registered JDBC drivers
that were loaded by the current ClassLoader
.
- An
Enumeration
of all currently loaded JDBC drivers.
getLogStream
public static PrintStream getLogStream()
Use getLogWriter()
instead.
This method returns the log stream in use by JDBC.
- The log stream in use by JDBC.
getLogWriter
public static PrintWriter getLogWriter()
This method returns the log writer being used by all JDBC drivers.
This method should be used in place of the deprecated
getLogStream
method.
- The log writer in use by JDBC drivers.
getLoginTimeout
public static int getLoginTimeout()
This method returns the login timeout in use by JDBC drivers systemwide.
println
public static void println(String message)
This method prints the specified line to the log stream.
message
- The string to write to the log stream.
registerDriver
public static void registerDriver(Driver driver)
throws SQLException
This method registers a new driver with the manager. This is normally
called by the driver itself in a static initializer.
driver
- The new Driver
to add.
setLogStream
public static void setLogStream(PrintStream stream)
Use setLogWriter
instead.
This method sets the log stream in use by JDBC.
stream
- The log stream in use by JDBC.
setLogWriter
public static void setLogWriter(PrintWriter out)
This method sets the log writer being used by JDBC drivers. This is a
system-wide parameter that affects all drivers. Note that since there
is no way to retrieve a PrintStream
from a
PrintWriter
, this method cannot set the log stream in
use by JDBC. Thus any older drivers may not see this setting.
out
- The new log writer for JDBC.
setLoginTimeout
public static void setLoginTimeout(int seconds)
This method set the login timeout used by JDBC drivers. This is a
system-wide parameter that applies to all drivers.
seconds
- The new login timeout value.
DriverManager.java -- Manage JDBC drivers
Copyright (C) 1999, 2000, 2001, 2003, 2004, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.