Java tries to connect to the database with MySQL through Eclipse editor

Source: Internet
Author: User
Tags ssl connection

Note: I am learning Oracle, using MySQL to connect to the database is an attempt.

One, download the JDBC MySQL driver, import the jar package

I downloaded the Connector-java-6.0.6.jar myself, as shown in the JDBC MySQL driver connection address http://mvnrepository.com/artifact/mysql/ mysql-connector-java/6.0.6,

Second, connect the database

Code such as:

Test class:

Then I run this main method, and the console appears with the following exception:

After that I will exception:

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) to use a more specifc Time zone value if you want to utilize time zone support.
At Com.mysql.cj.jdbc.exceptions.SQLError.createSQLException (sqlerror.java:545)

Search by Baidu, know my Url address is incorrect, and change it to: private static String url= "jdbc:mysql://localhost:3306/crm?useunicode=true& CHARACTERENCODING=UTF-8&SERVERTIMEZONE=UTC ";

Run the main method again, and the console results are as follows:

Then I press the console prompt to change the driver driver= "Com.mysql.jdbc.Driver" to driver= "Com.mysql.cj.jdbc.Driver"

To run the program again, the console appears with the following warning:

I will warn again: Tue 13:19:53 CST warn:establishing SSL connection without server ' s identity verification is not Recomm Ended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must is established by default if explicit Opti On isn ' t set. For compliance with existing applications not using SSL, the Verifyservercertificate property was set to ' false '. You need either to explicitly disable SSL by setting Usessl=false, or set usessl=true and provide truststore for server CE Rtificate verification.

Search through Baidu, and eventually change the value of the address URL to url=jdbc:mysql://localhost:3306/crm?useunicode=true&characterencoding=utf-8& SERVERTIMEZONE=UTC&usessl=false, and run the program again, the program eventually runs normally. The results are as follows:

Java tries to connect to the database with MySQL through Eclipse editor

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.