標籤:mys ons either creates error char jdb epo 匯入jar包
註:本人學的是Oracle,用mysql串連資料庫是一次嘗試。
一、下載JDBC mysql驅動,匯入jar包
我自己下載的是connector-java-6.0.6.jar,如所示,JDBC mysql驅動串連地址http://mvnrepository.com/artifact/mysql/mysql-connector-java/6.0.6,
二、串連資料庫
代碼如:
測試類別:
然後我運行這個主方法,控制台出現如下異常:
之後我將異常:
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.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:545)
通過百度尋找,知道我的Url地址不正確,並將其改為: private static String Url="jdbc:mysql://localhost:3306/crm?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC";
再次運行主方法,控制台結果如下:
接著我再按著控制台提示將驅動Driver="com.mysql.jdbc.Driver" 改為 Driver="com.mysql.cj.jdbc.Driver"
再次運行程式,控制台出現如下警告:
我再次將警告: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.
通過百度尋找,最終將地址Url的值改為Url=jdbc:mysql://localhost:3306/crm?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false,並再次運行程式,程式最終運行正常。結果如下:
java 通過eclipse編輯器用mysql嘗試 串連資料庫