This question already has answers here:
Warning about SSL connection when connecting to MySQL database
                                
                                    (13个回答)
                                
                        
                                2年前关闭。
            
                    
我的代码如下

import java.sql.*;


public class jbdcTrial {

    public static void main(String[] args) throws Exception{
        String dburl ="jdbc:mysql://localhost:3306/users";
        String username ="root";
        String password ="Calvin25;";


        try {

            Class.forName("com.mysql.jdbc.Driver");
            Connection myconnection = DriverManager.getConnection(dburl,username,password);


            Statement myStatement = myconnection.createStatement();


            ResultSet myresultset = myStatement.executeQuery("select * from employees");

            while(myresultset.next()) {
                 int count =myresultset.getInt(1);
                 System.out.println("count of stock : " + count);

            }
        } catch (SQLException e) {


        }

    }
}


我在Eclipse中将mysql连接器添加为jar库
我看到的唯一输出是这个


  Tue Feb 27 17:44:23 EAT 2018警告:不建议在没有服务器身份验证的情况下建立SSL连接。根据MySQL 5.5.45 +,5.6.26 +和5.7.6+的要求,如果未设置显式选项,则默认情况下必须建立SSL连接。为了与不使用SSL的现有应用程序兼容,将verifyServerCertificate属性设置为'false'。您需要通过设置useSSL = false显式禁用SSL,或设置useSSL = true并提供信任库以进行服务器证书验证。


但是在本教程中,它将显示数据库的输出以及该警告

最佳答案

尝试这个:

String dburl ="jdbc:mysql://localhost:3306/users?useSSL=false";

关于java - 我的Java应用程序不会显示mysql数据库的任何输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49011947/

10-14 11:53
查看更多