• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
7 views

Problem :

With my two classes I want to connect to the MySQL database. But, I always get below error:

Wed Dec 04 10:46:52 CET 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.

This is MyTestDatabase class with the main method:

public class MyTestDatabase {
    public static void main(String[] args) {
        Database mydb = new Database();
        try {
            mydb.connect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        mydb.close();
    }
}

This is the MyDatabase class:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MyDatabase {
    private Connection conn;
    public void connect() throws Exception{
        if(conn != null) return;
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new Exception("No database found");
        }
        String connectionURL = "jdbc:mysql://localhost:3303/Peoples";
        conn = DriverManager.getConnection(connectionURL, "root", "people23");        
    }
    public void close(){
        if(conn != null){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
by (7.5k points)  

1 Answer

0 votes

Solution :

The solution is very straightforward your connection URL should look like the following one:

jdbc:mysql://localhost:3303/Peoples?autoReconnect=true&useSSL=false

This will help you indisabling the SSL and will also suppress the SSL errors.

by (31.9k points)  
...