📄 drivermanager.java
字号:
public static synchronized void registerDriver(java.sql.Driver driver) throws SQLException { if (!initialized) { initialize(); } DriverInfo di = new DriverInfo(); di.driver = driver; di.className = driver.getClass().getName(); // Note our current securityContext. di.securityContext = getSecurityContext(); drivers.addElement(di); println("registerDriver: " + di); } /** * Drop a Driver from the DriverManager's list. Applets can only * deregister Drivers from their own classloader. * * @param driver the JDBC Driver to drop * @exception SQLException if a database-access error occurs. */ public static void deregisterDriver(Driver driver) throws SQLException { // Figure out the current security context. Object currentSecurityContext = getSecurityContext(); println("DriverManager.deregisterDriver: " + driver); // Walk through the loaded drivers. int i; DriverInfo di = null; for (i = 0; i < drivers.size(); i++) { di = (DriverInfo)drivers.elementAt(i); if (di.driver == driver) { break; } } // If we can't find the driver just return. if (i >= drivers.size()) { println(" couldn't find driver to unload"); return; } // If an applet is trying to free a driver from somewhere else // throw a security exception. if (currentSecurityContext != null && di.securityContext != currentSecurityContext) { throw new SecurityException(); } // Remove the driver. Other entries in drivers get shuffled down. drivers.removeElementAt(i); } /** * Return an Enumeration of all the currently loaded JDBC drivers * which the current caller has access to. * * <P><B>Note:</B> The classname of a driver can be found using * <CODE>d.getClass().getName()</CODE> * * @return the list of JDBC Drivers loaded by the caller's class loader */ public static java.util.Enumeration getDrivers() { java.util.Vector result = new java.util.Vector(); if (!initialized) { initialize(); } // Figure out the current security context. Object currentSecurityContext = getSecurityContext(); // Walk through the loaded drivers. for (int i = 0; i < drivers.size(); i++) { DriverInfo di = (DriverInfo)drivers.elementAt(i); // if the driver isn't part of the base system and doesn't come // from the same security context as the current caller, skip it. if (di.securityContext != null && di.securityContext != currentSecurityContext) { println(" skipping: " + di); continue; } result.addElement(di.driver); } return (result.elements()); } /** * Set the maximum time in seconds that all drivers can wait * when attempting to log in to a database. * * @param seconds the driver login time limit */ public static void setLoginTimeout(int seconds) { loginTimeout = seconds; } /** * Get the maximum time in seconds that all drivers can wait * when attempting to log in to a database. * * @return the driver login time limit */ public static int getLoginTimeout() { return (loginTimeout); } /** * Set the logging/tracing PrintStream that is used by the DriverManager * and all drivers. * * @param out the new logging/tracing PrintStream; to disable, set to null * @deprecated */ public static void setLogStream(java.io.PrintStream out) { logStream = out; if ( out != null ) logWriter = new java.io.PrintWriter(out); else logWriter = null; } /** * Get the logging/tracing PrintStream that is used by the DriverManager * and all drivers. * * @return the logging/tracing PrintStream; if disabled, is null * @deprecated */ public static java.io.PrintStream getLogStream() { return logStream; } /** * Print a message to the current JDBC log stream * * @param message a log or tracing message */ public static void println(String message) { if (logWriter != null) { logWriter.println(message); // automatic flushing is never enabled, so we must do it ourselves logWriter.flush(); } } //------------------------------------------------------------------------- private static Object getSecurityContext() { // Get the securityContext for our caller. For applets this // will be the applet classloader base URL. SecurityManager security = System.getSecurityManager(); if (security == null) { return (null); } return (security.getSecurityContext()); } private static void loadInitialDrivers() { String drivers; try { try { java.security.AccessController.beginPrivileged(); drivers = System.getProperty("jdbc.drivers"); } finally { java.security.AccessController.endPrivileged(); } } catch (Exception ex) { drivers = null; } println("DriverManager.initialize: jdbc.drivers = " + drivers); if (drivers == null) { return; } while (drivers.length() != 0) { int x = drivers.indexOf(':'); String driver; if (x < 0) { driver = drivers; drivers = ""; } else { driver = drivers.substring(0, x); drivers = drivers.substring(x+1); } if (driver.length() == 0) { continue; } try { println("DriverManager.Initialize: loading " + driver); Class.forName(driver); } catch (Exception ex) { println("DriverManager.Initialize: load failed: " + ex); } } } // Class initialization. static void initialize() { if (initialized) { return; } initialized = true; loadInitialDrivers(); println("JDBC DriverManager initialized"); } // Prevent the DriverManager class from being instantiated. private DriverManager(){} private static java.util.Vector drivers = new java.util.Vector(); private static int loginTimeout = 0; private static java.io.PrintWriter logWriter = null; private static java.io.PrintStream logStream = null; private static boolean initialized = false;}// DriverInfo is a package-private support class.class DriverInfo { Driver driver; Object securityContext; String className; public String toString() { return ("driver[className=" + className + ",context=" + securityContext + "," + driver + "]"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -