关于javajdbc链接数据库的问题
cinit> ,其中会调用 java.sql.DriverManager.registerDriver(new Driver()),把当前 Driver 包装成一个DriverInfo 放入到一个 DriverManager COW list 中,即 CopyOnWriteArrayList<DriverInfo> registeredDrivers。
public class Driver extends NonRegisteringDriver implements java.sql.Driver { // // Register ourselves with the DriverManager // static { try { java.sql.DriverManager.registerDriver(new Driver()); } catch (SQLException E) { throw new RuntimeException("Can't register driver!"); } } /** * Construct a new driver and register it with DriverManager * * @throws SQLException if a database error occurs. */ public Driver() throws SQLException { // Required for Class.forName().newInstance() } } 获取连接 DriverManager.getConnection() 时会遍历已经注册在 registeredDrivers 中的 DriverInfo,调用 connect 建立连接最终返回一个 java.sql.Connection。
private static Connection getConnection( // ... 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()); } } // ... }
注册驱动时通过 Class.forName("com.mysql.jdbc.Driver") 加载类并执行类初始化方法 <public class Driver extends NonRegisteringDriver implements java.sql.Driver { // // Register ourselves with the DriverManager // static { try { java.sql.DriverManager.registerDriver(new Driver()); } catch (SQLException E) { throw new RuntimeException("Can't register driver!"); } } /** * Construct a new driver and register it with DriverManager * * @throws SQLException if a database error occurs. */ public Driver() throws SQLException { // Required for Class.forName().newInstance() } } 获取连接 DriverManager.getConnection() 时会遍历已经注册在 registeredDrivers 中的 DriverInfo,调用 connect 建立连接最终返回一个 java.sql.Connection。
private static Connection getConnection( // ... 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()); } } // ... }
要利用吃碰停的成功可能可以更好,就在于掌握了基本规则的基础上,要勇敢的去求胜算,而且要利用规则的要点,掌握基本的技巧与方法,让赢牌顺利成功,可以成为巧妙赢的基础与重点。尤其是景德镇麻将怎么打的规则掌握当如,有取舍的目标来追求赢牌,同时还要考虑有原则配停的基础上,也让玩法的自由成为赢率提升的条件。
上一篇:激光产品出口美国FDA注册标准和法规指南 下一篇:哪里的海很蓝还有透明的感觉