0

I'm trying to connect to MySQL database:

       static final String URL="jdbc:mysql://localhost:3306/demo_hotels?useSSL=true&autoReconnect=true&serverTimezone=UTC";
       static final String USERNAME="demo";
       static final String PASSWORD="demo";

        public static void main(String[] args) {
         try {
          DriverManager.registerDriver(new FabricMySQLDriver());
          connection=DriverManager.getConnection(URL, USERNAME, PASSWORD);

          Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new
                JdbcConnection(connection));
          Liquibase liquibase = new liquibase.Liquibase("db/db.changelog.xml",
                new ClassLoaderResourceAccessor(), database);

          liquibase.update(new Contexts(), new LabelExpression());
          database.close();

         } catch (SQLException | LiquibaseException e) {
          e.printStackTrace();
         }

This was working. But now I'm trying to execute this code on another machine and it doesn't work:

    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
   at com.pazukdev.auxiliary_services.DBService.main(DBService.java:69)
    Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:
   at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:392)

Why did it stop to work?

Old machine: java version 1.8.0_112, Windows 7, MySQL Server 5.7.21

New machine: java version 1.8.0_172, Windows 10, MySQL Server 8.0.11

I found some information about such kind of exceptions. It look like I have some triobles with SSL certificate: Accept server's self-signed ssl certificate in Java client

But Option 2 with TrustManager not works - I have the same Exception. I tried to type in cmd:

<JAVA_HOME>\bin\keytool -import -v -trustcacerts
-alias server-alias -file server.cer
-keystore cacerts.jks -keypass changeit
-storepass changeit

But I have no eny effect from this Option 1 too.

Maybe I'm doing something wrong..

pazukdev
  • 155
  • 2
  • 13

2 Answers2

1

I'm not Java developer, but I have some doubts and questions here.

  1. Do you actually need for ?useSSL=true if you're using local db?
  2. What are the results of your cmd execution? Did you have correctly exported server.cer file corresponds to your local host? With necessary keypass and storepass?
Vitaly Filatenko
  • 415
  • 3
  • 12
  • 2. No, I'm not. And I'm not. I already got it, that I have done that stuff absolutely incorrect. I need to read about this to fix my ignorance in this task. But I'll do it later. Because now this issue already solved for me. – pazukdev Jun 06 '18 at 08:51
  • 1. No, don't. And this is the most right answer for my issue. Trying to solve issue with it, I got obsessed on this issue, stopped see whole the picture and forgot my true task. Yes, I really don't need in use of SSL. I switched it off. But I still had troubbles with connection. And it made me realise, that the real problem was not in stuff with SSL certificate only, but in my database. And this helped me solve my issue. – pazukdev Jun 06 '18 at 08:52
0

I had a global problem with database and connection to it. It was caused by that now I installed all the MySQL stuff in its lastest versions. And on my old machine I have the older versions of that software. So, I even had some exceptions trying to execute some of my old MySQL queries in new software.

I installed the same versions of MySQL Server and Connector/ODBC as I have on old machine (5.7.21 and 5.3.10 respectively) and got connection working properly as before.

pazukdev
  • 155
  • 2
  • 13