1、DriverManager:注册driver,其实是把这个driver存到了DriverManager里面的一个CopyOnWriteArrayList<DriverInfo>类型的变量里,名为registeredDrivers,然后在你java.sql.DriverManager.getConnection(String, Properties, Class<?>)里取出注册的链接。
registeredDrivers代码
static { try { java.sql.DriverManager.registerDriver(new Driver()); } catch (SQLException E) { throw new RuntimeException("Can't register driver!"); } }View Code
for(DriverInfo aDriver : registeredDrivers) { // If the caller does not have permission to load the driver then // skip it. if(isDriverAllowed(aDriver.driver, callerCL)) { try { println(" trying " + aDriver.driver.getClass().getName()); Connection con = aDriver.driver.connect(url, info); if (con != null) { // Success! println("getConnection returning " + aDriver.driver.getClass().getName()); return (con); } } catch (SQLException ex) { if (reason == null) { reason = ex; } } } else { println(" skipping: " + aDriver.getClass().getName()); } }View Code