• JDBC 笔记


      1、DriverManager:注册driver,其实是把这个driver存到了DriverManager里面的一个CopyOnWriteArrayList<DriverInfo>类型的变量里,名为registeredDrivers,然后在你java.sql.DriverManager.getConnection(String, Properties, Class<?>)里取出注册的链接。

      Driver类静态加载,Class forName("com.mysql.jdbc.Driver")

      不需要显式的注册:静态加载自动调用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
  • 相关阅读:
    G
    O
    M
    K-Hero
    J
    G
    F
    Codeforces Round #327 (Div. 2) A Wizards' Duel (水题)
    C++各大有名科学计算库(转)
    矩阵算法 高斯消元 行列式 矩阵的秩
  • 原文地址:https://www.cnblogs.com/GoldenEllipsis/p/15208823.html
Copyright © 2020-2023  润新知