连接高版本的MySQL时会报SSL 的提示信息

来源:互联网 发布:南极属于哪个国家 知乎 编辑:程序博客网 时间:2024/05/18 00:47

        String name = "";
        int age = 0;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://127.0.0.1:3306/gl";
            Connection conn = DriverManager.getConnection(url,"root","guolei");
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("select * from user ");
            while(rs.next()){
                name = rs.getString(1);
                age = rs.getInt(2);
                System.out.println(name+":"+age);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

java链接MySQL时会报如下错误:
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.
       

结局办法:重新定义url时加上useSSL属性

String url = "jdbc:mysql://127.0.0.1:3306/gl?useSSL=true";

0 0
原创粉丝点击