手写一个JDBC连接池

1.连接池的作用

连接池一般比直接连接更有优越性,因为它提高了性能的同时还保存了宝贵的资源。在整个应用程序的使用过程,当中重复的打开直接连接将导致性能的下降。而池连接只在服务器启动时打开一次,从而消除了这种性能问题。
        连接池主要考虑的是性能,每次获取连接和释放连接都有很大的工作量,会对性能有很大影响;而对资源来说起的是反作用,因为保存一定数量的连接是要消耗内存的。应用程序每次从池里获得Connection对象,而不是直接从数据里获得,这样不占用服务器的内存资源。所以一般要建立连接池,而连接的数量要适当,不能太大,太大会过多消耗资源。(所以,考虑2个方面,一个是内存,另一个是资源)。 连接池就是为了避免重复多次的打开数据库连接而造成的性能的下降和系统资源的浪费。

目前Java中使用连接池的三种方式:
a.自定义连接池
b.使用第三方连接池
c.使用服务器自带的连接池

在自定义连接池的使用上,上网查看了不少案例,自己总结了一下,不多说直接上代码。

2.pom文件


        
        
            mysql
            mysql-connector-java
            5.1.47
        

        
        
            org.projectlombok
            lombok
            1.18.8
        

        
            junit
            junit
            4.12
        

3.jdbc.properties

jdbc.driverName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.234.131:3306/bas_db
jdbc.username=root
jdbc.password=@WSX1qaz
jdbc.poolName=jdbcThread
jdbc.minConnections=5
jdbc.maxConnections=10
jdbc.initConnections=2
jdbc.connTimeOut=1000

4.DbBean

import lombok.Data;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@Data
public class DbBean {

    private  String driverName;

    private  String url;

    private  String userName ;

    private  String password ;

    private  String poolName ;// 连接池名字

    private  int minConnections; // 空闲池,最小连接数

    private  int maxConnections ; // 空闲池,最大连接数

    private  int initConnections ;// 初始化连接数

    private  long connTimeOut;// 重复获得连接的频率


    {
        readConfig();
    }

    private void readConfig() {
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("jdbc.properties");
        Properties prop = new Properties();
        if (null != inputStream){
            try {
                prop.load(inputStream);
                this.driverName = prop.getProperty("jdbc.driverName");
                this.url = prop.getProperty("jdbc.url");
                this.userName = prop.getProperty("jdbc.username");
                this.password = prop.getProperty("jdbc.password");
                this.poolName = prop.getProperty("jdbc.poolName");
                this.minConnections = Integer.parseInt(prop.getProperty("jdbc.minConnections"));
                this.maxConnections = Integer.parseInt(prop.getProperty("jdbc.maxConnections"));
                this.initConnections = Integer.parseInt(prop.getProperty("jdbc.initConnections"));
                this.connTimeOut = Long.parseLong(prop.getProperty("jdbc.connTimeOut"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

5.创建连接池

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 连接池
 */
public class ConnectionPoolManager {

    //空闲线程
    private List freeConnection = new Vector();

    //活跃线程
    private List activeConnection = new Vector();

    //连接数
    private AtomicInteger connCount = new AtomicInteger();

    //DbBean
    private DbBean dbBean = new DbBean();

    public ConnectionPoolManager() {
        this.init();
    }

    /**
     * 初始化
     */
    private void init() {
        for (int i = 0; i <= dbBean.getInitConnections(); i++) {
            Connection conn = this.CreateConnection();
            if (null != conn) {
                freeConnection.add(conn);
            }
        }
    }

    /**
     * 创建连接
     *
     * @return
     */
    private Connection CreateConnection() {

        try {

            if (null == dbBean) {
                return null;
            }
            Class.forName(dbBean.getDriverName());
            Connection conn = DriverManager.getConnection(dbBean.getUrl(), dbBean.getUserName(), dbBean.getPassword());
            connCount.decrementAndGet();
            return conn;

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 获取连接
     *
     * @return
     */
    public synchronized Connection getConnection() {

        Connection conn = null;
        try {
            //判断活跃线程是否大于等于最大连接数,大于等于则等待,
            if (activeConnection.size() >= dbBean.getMaxConnections()) {
                //大于等于,则等待
                wait(dbBean.getConnTimeOut());
                this.getConnection();
            } else {
                //小于
                //判断空闲线程数是否大于0,大于则直接从空闲线程中取
                if (freeConnection.size() > 0) {
                    //大于
                    conn = freeConnection.remove(0);
                } else {
                    //小于,则创建连接
                    conn = this.CreateConnection();
                }

                //判断连接是否有效
                if (isAvailable(conn)) {
                    //有效,放入活跃线程中
                    activeConnection.add(conn);
                } else {
                    conn = this.getConnection();
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return conn;
    }

    /**
     * 释放连接
     */
    public synchronized void releaseConnection(Connection conn) {

        if (!isAvailable(conn)) {
            return;
        }

        //判断空闲线程是否大于最小连接数,大于则关闭连接
        if (freeConnection.size() > dbBean.getMinConnections()) {
            //大于,直接关闭
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } else {
            //小于,空闲线程加1
            freeConnection.add(conn);
            this.connCount.decrementAndGet();
        }

    }

    /**
     * 判断连接是否有效
     *
     * @param conn
     * @return
     */
    public boolean isAvailable(Connection conn) {

        try {

            if (null == conn || conn.isClosed()) {
                return false;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }
}

6.测试

import java.sql.Connection;
import java.sql.PreparedStatement;

public class test {
    public static void main(String[] args) {

        final ConnectionPoolManager connectionPoolManager = new ConnectionPoolManager();

        for (int i = 0; i < 15; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        for (int y = 0; y < 10; y++) {
                            Connection connection = connectionPoolManager.getConnection();
                            PreparedStatement state = connection.prepareStatement("select * from u_user where id = 1");
                            System.out.println(state.executeQuery());
                            Thread.sleep(1);
                            connectionPoolManager.releaseConnection(connection);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }, "用户线程:" + i).start();
        }
    }
}

7.运行结果

Sun Jun 23 19:42:50 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
从数据库中获取连接:com.mysql.jdbc.JDBC4Connection@1a968a59,当前连接数:-1
Sun Jun 23 19:42:51 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
从数据库中获取连接:com.mysql.jdbc.JDBC4Connection@204f30ec,当前连接数:-2
Sun Jun 23 19:42:51 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
从数据库中获取连接:com.mysql.jdbc.JDBC4Connection@4dfa3a9d,当前连接数:-3
com.mysql.jdbc.JDBC42ResultSet@669da637
com.mysql.jdbc.JDBC42ResultSet@35b308c6
com.mysql.jdbc.JDBC42ResultSet@7bb245c

8.延伸

其实也可以按以下方法写,直接初始化连接数,每次使用后将连接放回,当连接满时,等待,直到连接有空闲

  • JDBCHelper

package com.jdbcPool.demo01;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.LinkedList;
import java.util.List;

/**
 * JDBC辅助组件
 *
 * @author Administrator
 */
public class JDBCHelper {

    private static JDBCHelper instance = null;
    private LinkedList datasource = new LinkedList();

    private static DbBean dbBean = new DbBean();

    //数据库连接池的大小
    private static final int POOL_SIZE = 30;
    /**
     * 第一步:在静态代码块中,直接加载数据库的驱动
     */
    static {
        try {
            Class.forName(dbBean.getDriverName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 第二步,实现JDBCHelper的单例化,为什么要实现代理化呢?因为它的内部要封装一个简单的内部的数据库连接池。
     * 为了保证数据库连接池有且仅有一份,所以就通过单例的方式。 保证JDBCHelper只有一个实例,实例中只有一份数据库连接池。
     */
    public static JDBCHelper getInstance() {
        if (instance == null) {
            synchronized (JDBCHelper.class) {
                if (instance == null) {
                    instance = new JDBCHelper();
                }
            }
        }
        return instance;
    }

    /**
     * 第三步:实现单例的过程中,创建唯一的数据库连接池。 JDBCHelper在整个程序运行声明周期中,只会创建一次实例。
     * 在这一次创建实例的过程中,就会调用JDBCHelper()构造方法 此时,就可以在构造方法中,去创建自己唯一的一个数据库连接池。
     */
    private JDBCHelper() {
        // 然后创建指定数量的数据库连接,并放入数据库连接池中
        for (int i = 0; i < POOL_SIZE; i++) {

            try {
                Connection conn = DriverManager.getConnection(dbBean.getUrl(), dbBean.getUserName(), dbBean.getPassword());
                datasource.push(conn);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 第四步,提供获取数据库连接的方法。有可能我们去获取的时候,这个时候连接都被用光了,我们暂时获取不到数据库连接。
     * 所以我们要自己编码实现一个简单的等待机制,去等待获取到数据库连接
     */
    public synchronized Connection getConnection() {
        while (datasource.size() == 0) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return datasource.poll();
    }

    /**
     * 第五步:开发增删改查的方法 1、执行增删改SQL语句的方法 2、执行查询SQL语句的方法 3、批量执行SQL语句的方法
     */

    /**
     * 执行增删改SQL语句
     *
     * @param sql
     * @param params
     * @return 影响的行数
     */
    public int executeUpdate(String sql, Object[] params) {
        int rtn = 0;
        Connection conn = null;
        PreparedStatement pstmt = null;

        try {
            conn = getConnection();
            conn.setAutoCommit(false);

            pstmt = conn.prepareStatement(sql);

            if (params != null && params.length > 0) {
                for (int i = 0; i < params.length; i++) {
                    pstmt.setObject(i + 1, params[i]);
                }
            }

            rtn = pstmt.executeUpdate();

            conn.commit();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (conn != null) {
                datasource.push(conn);
            }
        }

        return rtn;
    }

    /**
     * 执行查询SQL语句
     *
     * @param sql
     * @param params
     * @param callback
     */
    public void executeQuery(String sql, Object[] params, QueryCallback callback) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            conn = getConnection();
            pstmt = conn.prepareStatement(sql);

            if (params != null && params.length > 0) {
                for (int i = 0; i < params.length; i++) {
                    pstmt.setObject(i + 1, params[i]);
                }
            }

            rs = pstmt.executeQuery();

            callback.process(rs);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (conn != null) {
                datasource.push(conn);
            }
        }
    }

    /**
     * 批量执行SQL语句
     * 

* 批量执行SQL语句,是JDBC中的一个高级功能 默认情况下,每次执行一条SQL语句,就会通过网络连接,向MySQL发送一次请求 *

* 但是,如果在短时间内要执行多条结构完全一模一样的SQL,只是参数不同 * 虽然使用PreparedStatement这种方式,可以只编译一次SQL,提高性能,但是,还是对于每次SQL 都要向MySQL发送一次网络请求 *

* 可以通过批量执行SQL语句的功能优化这个性能 一次性通过PreparedStatement发送多条SQL语句,比如100条、1000条,甚至上万条 * 执行的时候,也仅仅编译一次就可以 这种批量执行SQL语句的方式,可以大大提升性能 * * @param sql * @param paramsList * @return 每条SQL语句影响的行数 */ public int[] executeBatch(String sql, List paramsList) { int[] rtn = null; Connection conn = null; PreparedStatement pstmt = null; try { conn = getConnection(); // 第一步:使用Connection对象,取消自动提交 conn.setAutoCommit(false); pstmt = conn.prepareStatement(sql); // 第二步:使用PreparedStatement.addBatch()方法加入批量的SQL参数 if (paramsList != null && paramsList.size() > 0) { for (Object[] params : paramsList) { for (int i = 0; i < params.length; i++) { pstmt.setObject(i + 1, params[i]); } pstmt.addBatch(); } } // 第三步:使用PreparedStatement.executeBatch()方法,执行批量的SQL语句 rtn = pstmt.executeBatch(); // 最后一步:使用Connection对象,提交批量的SQL语句 conn.commit(); } catch (Exception e) { e.printStackTrace(); } finally { if (conn != null) { datasource.push(conn); } } return rtn; } /** * 静态内部类:查询回调接口 * * @author Administrator */ public static interface QueryCallback { /** * 处理查询结果 * * @param resultSet * @throws Exception */ void process(ResultSet resultSet) throws Exception; } }

  • 测试

package com.jdbcPool.demo01;

import java.sql.ResultSet;

public class test01 {

    public static void main(String[] args) {
        final JDBCHelper jdbcHelper = JDBCHelper.getInstance();
        final Object[] params = {1};

        for (int i = 0; i < 15; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        for (int y = 0; y < 10; y++) {
                            jdbcHelper.executeQuery("select * from u_user where id=?", params, new JDBCHelper.QueryCallback() {
                                @Override
                                public void process(ResultSet resultSet) throws Exception {
                                    if (resultSet != null) {
                                        while (resultSet.next()) {
                                            System.out.println(resultSet.getString("name"));
                                        }
                                    }
                                }
                            });
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }, "用户线程:" + i).start();
        }


    }

}
  • 输入结果

"C:\Program Files\Java\jdk1.8.0_151\bin\java.exe" "-javaagent:F:\tools\idea\IntelliJ IDEA 2018.3.2\lib\idea_rt.jar=57752:F:\tools\idea\IntelliJ IDEA 2018.3.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_151\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\rt.jar;F:\FR\IDEA\mybatis\jdbcPool\target\classes;F:\dev\repo\mysql\mysql-connector-java\5.1.47\mysql-connector-java-5.1.47.jar;F:\dev\repo\org\projectlombok\lombok\1.18.8\lombok-1.18.8.jar;F:\dev\repo\junit\junit\4.12\junit-4.12.jar;F:\dev\repo\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar" com.jdbcPool.demo01.test01
Sun Jun 23 22:08:39 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:39 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:39 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:40 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:41 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Jun 23 22:08:41 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌
张无忌

Process finished with exit code 0

 

你可能感兴趣的:(手写一个JDBC连接池)