How to disable “Establishing SSL connection without server's identity verification is not recommended” warning when connecting to MySQL database in Java?


To disable the warning while connecting to a database in Java, use the below concept −

autoReconnect=true&useSSL=false

The complete syntax is as follows −

yourJdbcURL="jdbc:mysql://localhost:yourPortNumber/yourDatabaseName?autoReconnect=true&useSSL=false";

Here is the warning message if you do not include “useSSL=false” −

Wed Feb 06 18:53:39 IST 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.

The snapshot is as follows −

If you want to avoid the above MySQL warning, use the syntax mention in the beginning.

The Java code is as follows −

import java.sql.Connection;
import java.sql.DriverManager;
public class AvoidSQLWarnDemo {
   public static void main(String[] args) {
      String JdbcURL = "jdbc:mysql://localhost:3306/mybusiness?" + "autoReconnect=true&useSSL=false";
      String Username = "root";
      String password = "123456";
      Connection con = null;
      try {
         con = DriverManager.getConnection(JdbcURL, Username, password);
         System.out.println("Your JDBC URL is as follows:" + JdbcURL);
      } catch (Exception exec) {
         exec.printStackTrace();
      }
   }
}

After running the above java program, you won’t get the warning. However, you will get the following output −

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

11K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements