0

I am trying to connect my code to the database in linux i use the same code in windows it works fine but once i use it in linux it doesn't the information on my machine should be the same since i am using a virtual box for linux so if it works on windows it should work on linux .

public String DataBaseGetCode(String Email) {
    Reporter.log("</br>- Performed Action : Extracting Data from DB");
    // final String JDBC_DRIVER = "com.mysql.jdc.Driver";
    final String DB_URL = "jdbc:mysql://23.465.165.568:3306/test";

    // DataBase Credentials
    final String User = "test";
    final String Password = "test";

    // DataBase Data
    String CodeSMS = null;
    Connection con = null;
    Statement stmt = null;

    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
        try {
            // Open Connection
            con = DriverManager.getConnection(DB_URL, User, Password);

            // Execute Query
            stmt = con.createStatement();
            String SqlQuery = "SELECT code FROM `table` WHERE email ='" + Email + "'";
            System.out.println(SqlQuery);
            ResultSet executeQuery = stmt.executeQuery(SqlQuery);
            System.out.println(executeQuery);
            // Extract Data From query
            if (executeQuery.next()) {
                CodeSMS = executeQuery.getString("code");
                Reporter.log(FormatMessageSucces + " Data extracted Correctly</font>");
            }
            // Close All Connections
            executeQuery.close();
            stmt.close();
            con.close();

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return CodeSMS;
}

Sadly i have this error message that shows and i dont have the smallest idea why it s happening :

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at MecaGOO.Functions.TESTDataBaseGetCode(Functions.java:732)
    at MecaGOO.FaireCommande.TakeAppointementWithoutAccount(FaireCommande.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:645)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:756)
    at org.testng.TestRunner.run(TestRunner.java:610)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
    at org.testng.SuiteRunner.run(SuiteRunner.java:289)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
    at org.testng.TestNG.runSuites(TestNG.java:1133)
    at org.testng.TestNG.run(TestNG.java:1104)
    at org.testng.TestNG.privateMain(TestNG.java:1434)
    at org.testng.TestNG.main(TestNG.java:1403)
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
    
    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
    at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
    at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:361)
    at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:777)
    at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:486)
    at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:202)
    at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1449)
    at com.mysql.cj.NativeSession.connect(NativeSession.java:165)
    at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
        ... 31 more
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
    at sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:171)
    at sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:98)
    at sun.security.ssl.TransportContext.kickstart(TransportContext.java:220)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:428)
    at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:315)
    at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188)
    at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99)
    at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:352)
        ... 38 more
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Yan
  • 108
  • 1
  • 8
  • One can test with an SQL tool. Probably fire wall? – Joop Eggen Dec 15 '21 at 14:34
  • @JoopEggen i was abel to connect to the database from terminal – Yan Dec 15 '21 at 14:39
  • What version of MySQL, MySQL Connector/J and Java are you using? Full versions please. – Mark Rotteveel Dec 15 '21 at 14:50
  • for java it s 8 for mysql it s not local so i am not sure what version it is – Yan Dec 15 '21 at 14:51
  • I asked for the full versions. "Java 8" is not a full version and you should know your MySQL Connector/J version. In any case, see [Why can Java not connect to MySQL 5.7 after the latest JDK update and how should it be fixed? (ssl.SSLHandshakeException: No appropriate protocol)](https://stackoverflow.com/questions/67332909/why-can-java-not-connect-to-mysql-5-7-after-the-latest-jdk-update-and-how-should) might help you. – Mark Rotteveel Dec 15 '21 at 14:53

0 Answers0