| Method from java.sql.DriverManager Detail: |
public static synchronized void deregisterDriver(Driver driver) throws SQLException {
// Gets the classloader of the code that called this method,
// may be null.
ClassLoader callerCL = DriverManager.getCallerClassLoader();
println("DriverManager.deregisterDriver: " + driver);
// Walk through the loaded drivers.
int i;
DriverInfo di = null;
for (i = 0; i < writeDrivers.size(); i++) {
di = (DriverInfo)writeDrivers.elementAt(i);
if (di.driver == driver) {
break;
}
}
// If we can't find the driver just return.
if (i >= writeDrivers.size()) {
println(" couldn't find driver to unload");
return;
}
// If the caller does not have permission to load the driver then
// throw a security exception.
if (getCallerClass(callerCL, di.driverClassName ) != di.driverClass ) {
throw new SecurityException();
}
// Remove the driver. Other entries in drivers get shuffled down.
writeDrivers.removeElementAt(i);
/* update the read copy of drivers vector */
readDrivers = (java.util.Vector) writeDrivers.clone();
}
Drops a driver from the DriverManager's list.
Applets can only deregister drivers from their own classloaders. |
public static Connection getConnection(String url) throws SQLException {
java.util.Properties info = new java.util.Properties();
// Gets the classloader of the code that called this method, may
// be null.
ClassLoader callerCL = DriverManager.getCallerClassLoader();
return (getConnection(url, info, callerCL));
}
Attempts to establish a connection to the given database URL.
The DriverManager attempts to select an appropriate driver from
the set of registered JDBC drivers. |
public static Connection getConnection(String url,
Properties info) throws SQLException {
// Gets the classloader of the code that called this method, may
// be null.
ClassLoader callerCL = DriverManager.getCallerClassLoader();
return (getConnection(url, info, callerCL));
}
Attempts to establish a connection to the given database URL.
The DriverManager attempts to select an appropriate driver from
the set of registered JDBC drivers. |
public static Connection getConnection(String url,
String user,
String password) throws SQLException {
java.util.Properties info = new java.util.Properties();
// Gets the classloader of the code that called this method, may
// be null.
ClassLoader callerCL = DriverManager.getCallerClassLoader();
if (user != null) {
info.put("user", user);
}
if (password != null) {
info.put("password", password);
}
return (getConnection(url, info, callerCL));
}
Attempts to establish a connection to the given database URL.
The DriverManager attempts to select an appropriate driver from
the set of registered JDBC drivers. |
public static Driver getDriver(String url) throws SQLException {
java.util.Vector drivers = null;
println("DriverManager.getDriver(\"" + url + "\")");
if (!initialized) {
initialize();
}
synchronized (DriverManager.class){
// use the read copy of the drivers vector
drivers = readDrivers;
}
// Gets the classloader of the code that called this method, may
// be null.
ClassLoader callerCL = DriverManager.getCallerClassLoader();
// Walk through the loaded drivers attempting to locate someone
// who understands the given URL.
for (int i = 0; i < drivers.size(); i++) {
DriverInfo di = (DriverInfo)drivers.elementAt(i);
// If the caller does not have permission to load the driver then
// skip it.
if ( getCallerClass(callerCL, di.driverClassName ) !=
di.driverClass ) {
println(" skipping: " + di);
continue;
}
try {
println(" trying " + di);
if (di.driver.acceptsURL(url)) {
// Success!
println("getDriver returning " + di);
return (di.driver);
}
} catch (SQLException ex) {
// Drop through and try the next driver.
}
}
println("getDriver: no suitable driver");
throw new SQLException("No suitable driver", "08001");
}
Attempts to locate a driver that understands the given URL.
The DriverManager attempts to select an appropriate driver from
the set of registered JDBC drivers. |
public static Enumeration<Driver> getDrivers() {
java.util.Vector< Driver > result = new java.util.Vector< Driver >();
java.util.Vector drivers = null;
if (!initialized) {
initialize();
}
synchronized (DriverManager.class){
// use the readcopy of drivers
drivers = readDrivers;
}
// Gets the classloader of the code that called this method, may
// be null.
ClassLoader callerCL = DriverManager.getCallerClassLoader();
// Walk through the loaded drivers.
for (int i = 0; i < drivers.size(); i++) {
DriverInfo di = (DriverInfo)drivers.elementAt(i);
// If the caller does not have permission to load the driver then
// skip it.
if ( getCallerClass(callerCL, di.driverClassName ) != di.driverClass ) {
println(" skipping: " + di);
continue;
}
result.addElement(di.driver);
}
return (result.elements());
}
|
public static PrintStream getLogStream() {
return logStream;
} Deprecated!
Retrieves the logging/tracing PrintStream that is used by the DriverManager
and all drivers. |
public static PrintWriter getLogWriter() {
return logWriter;
}
Retrieves the log writer.
The getLogWriter and setLogWriter
methods should be used instead
of the get/setlogStream methods, which are deprecated. |
public static int getLoginTimeout() {
return (loginTimeout);
}
Gets the maximum time in seconds that a driver can wait
when attempting to log in to a database. |
static void initialize() {
if (initialized) {
return;
}
initialized = true;
loadInitialDrivers();
println("JDBC DriverManager initialized");
}
|
public static void println(String message) {
synchronized (logSync) {
if (logWriter != null) {
logWriter.println(message);
// automatic flushing is never enabled, so we must do it ourselves
logWriter.flush();
}
}
}
Prints a message to the current JDBC log stream. |
public static synchronized void registerDriver(Driver driver) throws SQLException {
if (!initialized) {
initialize();
}
DriverInfo di = new DriverInfo();
di.driver = driver;
di.driverClass = driver.getClass();
di.driverClassName = di.driverClass.getName();
// Not Required -- drivers.addElement(di);
writeDrivers.addElement(di);
println("registerDriver: " + di);
/* update the read copy of drivers vector */
readDrivers = (java.util.Vector) writeDrivers.clone();
}
Registers the given driver with the DriverManager.
A newly-loaded driver class should call
the method registerDriver to make itself
known to the DriverManager. |
public static void setLogStream(PrintStream out) {
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkPermission(SET_LOG_PERMISSION);
}
logStream = out;
if ( out != null )
logWriter = new java.io.PrintWriter(out);
else
logWriter = null;
} Deprecated!
Sets the logging/tracing PrintStream that is used
by the DriverManager
and all drivers.
In the Java 2 SDK, Standard Edition, version 1.3 release, this method checks
to see that there is an SQLPermission object before setting
the logging stream. If a SecurityManager exists and its
checkPermission method denies setting the log writer, this
method throws a java.lang.SecurityException. |
public static void setLogWriter(PrintWriter out) {
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkPermission(SET_LOG_PERMISSION);
}
logStream = null;
logWriter = out;
}
Sets the logging/tracing PrintWriter object
that is used by the DriverManager and all drivers.
There is a minor versioning problem created by the introduction
of the method setLogWriter. The
method setLogWriter cannot create a PrintStream object
that will be returned by getLogStream---the Java platform does
not provide a backward conversion. As a result, a new application
that uses setLogWriter and also uses a JDBC 1.0 driver that uses
getLogStream will likely not see debugging information written
by that driver.
Starting with the Java 2 SDK, Standard Edition, version 1.3 release, this method checks
to see that there is an SQLPermission object before setting
the logging stream. If a SecurityManager exists and its
checkPermission method denies setting the log writer, this
method throws a java.lang.SecurityException. |
public static void setLoginTimeout(int seconds) {
loginTimeout = seconds;
}
Sets the maximum time in seconds that a driver will wait
while attempting to connect to a database. |