0
package dbb;

import java.sql.*;

public class test {
    public static void main (String[] args) {
        String url = "jdbc:mysql://localhost:3306/test";
        String user = "root";
        String pass = "1234";

        Connection conn = null;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("Driver Searched");
            conn = DriverManager.getConnection(url, user, pass);
            System.out.println("Connection Succeed" + conn);
        } catch (ClassNotFoundException e) {
            System.out.println("Driver Not Searched");
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

i made this code on java, but there are some errors. for example, enter image description here.

It shows that Driver is already searched, but the connection is still failed.

How can i fix the error?

garden lee
  • 21
  • 7
  • 6
    Add stacktraces as text not as image – Jens Apr 26 '18 at 06:42
  • https://stackoverflow.com/questions/34189756/warning-about-ssl-connection-when-connecting-to-mysql-database – xiaofeng.li Apr 26 '18 at 06:46
  • 1
    Possible duplicate: https://stackoverflow.com/questions/26515700/mysql-jdbc-driver-5-1-33-time-zone-issue – Andreas Fester Apr 26 '18 at 06:46
  • 2
    You can do the things suggested by the error log: use `com.mysql.cj.jdbc.Driver`; Disable SSL by adding `useSSL=false` to the url. The timezone value looks like something from a SSL handshake. – xiaofeng.li Apr 26 '18 at 06:51
  • Possible duplicate of [The server time zone value 'AEST' is unrecognized or represents more than one time zone](https://stackoverflow.com/questions/37719818/the-server-time-zone-value-aest-is-unrecognized-or-represents-more-than-one-ti) – Piro Apr 26 '18 at 07:05
  • Which version of MySQL and which version of MySQL Connector/J. And please replace the image with the stacktrace as text. – Mark Rotteveel Apr 26 '18 at 07:39

2 Answers2

1
public static void main(String[] args) {

    String url = "jdbc:mysql://localhost:3306/test";
    String user = "root";
    String pass = "Admin@123";

    java.sql.Connection conn = null;

    try {
        Class.forName("com.mysql.jdbc.Driver");
        System.out.println("Driver Searched");
        conn = DriverManager.getConnection(url, user, pass);
        System.out.println("Connection Succeed" + conn);
    } catch (ClassNotFoundException e) {
        System.out.println("Driver Not Searched");
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

it's working fine in my system with mysql-connector-java-5.1.6jar. Might be This is an issue with the MySql driver.

You can try with below : you might need to explicitly specify timezone in you jdbc url.:

String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
  • Connector/J 5.1.6 is really ancient (it was released in 2008), the latest 5.1.x is 5.1.46 from March 2018, the latest version is 8.0.11 from last week (2018-04-19). – Mark Rotteveel Apr 26 '18 at 08:44
0

As already suggested in the comment to use non-ssl connection with latest driver, you should use below code:

package dbb;
import java.sql.*;

public class test {
public static void main (String[] args) {
    String url = "jdbc:mysql://localhost:3306/test?useSSL=false";
    String user = "root";
    String pass = "1234";

    Connection conn = null;

    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
        System.out.println("Driver Searched");
        conn = DriverManager.getConnection(url, user, pass);
        System.out.println("Connection Succeed" + conn);
    } catch (ClassNotFoundException e) {
        System.out.println("Driver Not Searched");
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
}
Avinash Sagar
  • 527
  • 4
  • 10
  • still there are problem!! HERE: java.sql.SQLException: The server time zone value '´???¹?±¹ ???ؽ?' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. – garden lee Apr 26 '18 at 06:59
  • Please share the stack trace. – Avinash Sagar Apr 26 '18 at 06:59
  • SLL part is just warning – Piro Apr 26 '18 at 07:00
  • and this: Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '´???¹?±¹ ???ؽ?' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. – garden lee Apr 26 '18 at 07:00
  • Please refer to the URL provided [link](https://stackoverflow.com/questions/26515700/mysql-jdbc-driver-5-1-33-time-zone-issue?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa")[link] – Avinash Sagar Apr 26 '18 at 07:03