Method from java.sql.DriverManager Detail: |
public static synchronized void deregisterDriver(Driver driver) throws SQLException {
if (driver == null) {
return;
}
// Gets the classloader of the code that called this method,
// may be null.
ClassLoader callerCL = DriverManager.getCallerClassLoader();
println("DriverManager.deregisterDriver: " + driver);
DriverInfo aDriver = new DriverInfo(driver);
if(registeredDrivers.contains(aDriver)) {
if (isDriverAllowed(driver, callerCL)) {
registeredDrivers.remove(aDriver);
} else {
// If the caller does not have permission to load the driver then
// throw a SecurityException.
throw new SecurityException();
}
} else {
println(" couldn't find driver to unload");
}
}
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 {
println("DriverManager.getDriver(\"" + url + "\")");
// Gets the classloader of the code that called this method, may
// be null.
ClassLoader callerCL = DriverManager.getCallerClassLoader();
// Walk through the loaded registeredDrivers attempting to locate someone
// who understands the given URL.
for (DriverInfo aDriver : registeredDrivers) {
// If the caller does not have permission to load the driver then
// skip it.
if(isDriverAllowed(aDriver.driver, callerCL)) {
try {
if(aDriver.driver.acceptsURL(url)) {
// Success!
println("getDriver returning " + aDriver.driver.getClass().getName());
return (aDriver.driver);
}
} catch(SQLException sqe) {
// Drop through and try the next driver.
}
} else {
println(" skipping: " + aDriver.driver.getClass().getName());
}
}
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 >();
// Gets the classloader of the code that called this method, may
// be null.
ClassLoader callerCL = DriverManager.getCallerClassLoader();
// Walk through the loaded registeredDrivers.
for(DriverInfo aDriver : registeredDrivers) {
// If the caller does not have permission to load the driver then
// skip it.
if(isDriverAllowed(aDriver.driver, callerCL)) {
result.addElement(aDriver.driver);
} else {
println(" skipping: " + aDriver.getClass().getName());
}
}
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. |
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 {
/* Register the driver if it has not already been added to our list */
if(driver != null) {
registeredDrivers.addIfAbsent(new DriverInfo(driver));
} else {
// This is for compatibility with the original DriverManager
throw new NullPointerException();
}
println("registerDriver: " + driver);
}
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. |