Methods Summary |
---|
private static void | checkLogSecurity()
SecurityManager securityManager = System.getSecurityManager();
if (securityManager != null) {
// Throws a SecurityException if setting the log is not permitted
securityManager.checkPermission(logPermission);
}
|
public static void | deregisterDriver(java.sql.Driver driver)Removes a driver from the {@code 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 {@code DriverManager} will not use this
driver in the future when asked to get a {@code Connection}.
if (driver == null) {
return;
}
// BEGIN android-changed
ClassLoader callerClassLoader = VMStack.getCallingClassLoader();
// END android-changed
if (!DriverManager.isClassFromClassLoader(driver, callerClassLoader)) {
// sql.1=DriverManager: calling class not authorized to deregister JDBC driver
throw new SecurityException(Messages.getString("sql.1")); //$NON-NLS-1$
} // end if
synchronized (theDriverSet) {
theDriverSet.remove(driver);
}
|
public static java.sql.Connection | getConnection(java.lang.String url)Attempts to establish a connection to the given database URL.
return getConnection(url, new Properties());
|
public static java.sql.Connection | getConnection(java.lang.String url, java.util.Properties info)Attempts to establish a connection to the given database URL.
// 08 - connection exception
// 001 - SQL-client unable to establish SQL-connection
String sqlState = "08001"; //$NON-NLS-1$
if (url == null) {
// sql.5=The url cannot be null
throw new SQLException(Messages.getString("sql.5"), sqlState); //$NON-NLS-1$
}
synchronized (theDriverSet) {
/*
* Loop over the drivers in the DriverSet checking to see if one can
* open a connection to the supplied URL - return the first
* connection which is returned
*/
for (Driver theDriver : theDriverSet) {
Connection theConnection = theDriver.connect(url, info);
if (theConnection != null) {
return theConnection;
}
}
}
// If we get here, none of the drivers are able to resolve the URL
// sql.6=No suitable driver
throw new SQLException(Messages.getString("sql.6"), sqlState); //$NON-NLS-1$
|
public static java.sql.Connection | getConnection(java.lang.String url, java.lang.String user, java.lang.String password)Attempts to establish a connection to the given database URL.
Properties theProperties = new Properties();
if(null != user){
theProperties.setProperty("user", user); //$NON-NLS-1$
}
if(null != password){
theProperties.setProperty("password", password); //$NON-NLS-1$
}
return getConnection(url, theProperties);
|
public static java.sql.Driver | getDriver(java.lang.String url)Tries to find a driver that can interpret the supplied URL.
// BEGIN android-changed
ClassLoader callerClassLoader = VMStack.getCallingClassLoader();
// END android-changed
synchronized (theDriverSet) {
/*
* Loop over the drivers in the DriverSet checking to see if one
* does understand the supplied URL - return the first driver which
* does understand the URL
*/
Iterator<Driver> theIterator = theDriverSet.iterator();
while (theIterator.hasNext()) {
Driver theDriver = theIterator.next();
if (theDriver.acceptsURL(url)
&& DriverManager.isClassFromClassLoader(theDriver,
callerClassLoader)) {
return theDriver;
}
}
}
// If no drivers understand the URL, throw an SQLException
// sql.6=No suitable driver
//SQLState: 08 - connection exception
//001 - SQL-client unable to establish SQL-connection
throw new SQLException(Messages.getString("sql.6"), "08001"); //$NON-NLS-1$ //$NON-NLS-2$
|
public static java.util.Enumeration | getDrivers()Returns an {@code Enumeration} that contains all of the loaded JDBC
drivers that the current caller can access.
// BEGIN android-changed
ClassLoader callerClassLoader = VMStack.getCallingClassLoader();
// END android-changed
/*
* Synchronize to avoid clashes with additions and removals of drivers
* in the DriverSet
*/
synchronized (theDriverSet) {
/*
* Create the Enumeration by building a Vector from the elements of
* the DriverSet
*/
Vector<Driver> theVector = new Vector<Driver>();
Iterator<Driver> theIterator = theDriverSet.iterator();
while (theIterator.hasNext()) {
Driver theDriver = theIterator.next();
if (DriverManager.isClassFromClassLoader(theDriver,
callerClassLoader)) {
theVector.add(theDriver);
}
}
return theVector.elements();
}
|
public static java.io.PrintStream | getLogStream()Gets the log {@code PrintStream} used by the {@code DriverManager} and
all the JDBC Drivers.
return thePrintStream;
|
public static java.io.PrintWriter | getLogWriter()Retrieves the log writer.
return thePrintWriter;
|
public static int | getLoginTimeout()Returns the login timeout when connecting to a database in seconds.
return loginTimeout;
|
private static boolean | isClassFromClassLoader(java.lang.Object theObject, java.lang.ClassLoader theClassLoader)Determines whether the supplied object was loaded by the given {@code ClassLoader}.
if ((theObject == null) || (theClassLoader == null)) {
return false;
}
Class<?> objectClass = theObject.getClass();
try {
Class<?> checkClass = Class.forName(objectClass.getName(), true,
theClassLoader);
if (checkClass == objectClass) {
return true;
}
} catch (Throwable t) {
// Empty
}
return false;
|
private static void | loadInitialDrivers() //$NON-NLS-1$
/*
* Load drivers on initialization
*/
loadInitialDrivers();
String theDriverList = System.getProperty("jdbc.drivers", null); //$NON-NLS-1$
if (theDriverList == null) {
return;
}
/*
* Get the names of the drivers as an array of Strings from the system
* property by splitting the property at the separator character ':'
*/
String[] theDriverNames = theDriverList.split(":"); //$NON-NLS-1$
for (String element : theDriverNames) {
try {
// Load the driver class
Class
.forName(element, true, ClassLoader
.getSystemClassLoader());
} catch (Throwable t) {
// Ignored
}
}
|
public static void | println(java.lang.String message)Prints a message to the current JDBC log stream. This is either the
{@code PrintWriter} or (deprecated) the {@code PrintStream}, if set.
if (thePrintWriter != null) {
thePrintWriter.println(message);
thePrintWriter.flush();
} else if (thePrintStream != null) {
thePrintStream.println(message);
thePrintStream.flush();
}
/*
* If neither the PrintWriter not the PrintStream are set, then silently
* do nothing the message is not recorded and no exception is generated.
*/
return;
|
public static void | registerDriver(java.sql.Driver driver)Registers a given JDBC driver with the {@code DriverManager}.
A newly loaded JDBC driver class should register itself with the
{@code DriverManager} by calling this method.
if (driver == null) {
throw new NullPointerException();
}
synchronized (theDriverSet) {
theDriverSet.add(driver);
}
|
public static void | setLogStream(java.io.PrintStream out)Sets the print stream to use for logging data from the {@code
DriverManager} and the JDBC drivers.
checkLogSecurity();
thePrintStream = out;
|
public static void | setLogWriter(java.io.PrintWriter out)Sets the {@code PrintWriter} that is used by all loaded drivers, and also
the {@code DriverManager}.
checkLogSecurity();
thePrintWriter = out;
|
public static void | setLoginTimeout(int seconds)Sets the login timeout when connecting to a database in seconds.
loginTimeout = seconds;
return;
|