警告:建议不要在没有服务器身份验证的情况下建立SSL连接

rel*_*ari 20 java mysql

连接MySQL数据库时,我收到以下警告:

建议不要在没有服务器身份验证的情况下建立SSL连接.根据MySQL 5.5.45 +,5.6.26 +和5.7.6+要求如果未设置显式选项,则必须默认建立SSL连接.为了符合不使用SSL的现有应用程序,verifyServerCertificate属性设置为"false".您需要通过设置useSSL = false显式禁用SSL,或者设置useSSL = true并为服务器证书验证提供信任库.

请帮我解决这个问题

import java.sql.*;
public class JdbcCreateTable {
public static void main(String args[])
{
    try
    {
        Class.forName("com.mysql.jdbc.Driver");
    }
    catch(ClassNotFoundException e)
    {
        e.printStackTrace();
    }
    try{
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/INTtech","root","root");
        Statement st=con.createStatement();
        int i=st.executeUpdate("create table Author(AID int primary key,Aname varchar(20),AContact no int,ACountry string)");
        System.out.println("Table is created"+i);
        con.close();
    }
    catch(SQLException e)
    {
        e.printStackTrace();
    }
}
}
Run Code Online (Sandbox Code Playgroud)

小智 48

将useSSL = false放在名称数据库的末尾:

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/INTtech?useSSL=false","root","root");
Run Code Online (Sandbox Code Playgroud)

  • 我面临同样的错误,我在我的代码中添加了useSSL = false但它不起作用.你有什么其他的建议? (3认同)