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