Java uses the eclipse editor to use mysql to connect to the database, eclipsemysql

Source: Internet
Author: User
Tags ssl connection

Java uses the eclipse editor to use mysql to connect to the database, eclipsemysql

Note: I learned Oracle and it was an attempt to connect to the database using mysql.

 

1. Download The JDBC mysql driver and 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,

2. Connect to the database

The Code is as follows:

Test class:

Then, when I run this main method, the console displays the following exception:

Then I will be exception:

Java. SQL. SQLException: The server time zone value '? Why ??????? '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.
At com. mysql. cj. jdbc. exceptions. SQLError. createSQLException (SQLError. java: 545)

I found my Url through Baidu and changed it to private static String Url = "jdbc: mysql: // localhost: 3306/crm? UseUnicode = true & characterEncoding = UTF-8 & serverTimezone = UTC ";

Run the main method again. The console result is as follows:

Then I followed the console prompts to change the Driver = "com. mysql. jdbc. Driver" to Driver = "com. mysql. cj. jdbc. Driver"

Run the program again and the console displays the following warning:

I will WARN again: Tue Nov 14 13:19:53 CST 2017 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.

Through Baidu search, the Url value is changed 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 result is as follows:

 

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.