java 通過eclipse編輯器用mysql嘗試 串連資料庫

來源:互聯網
上載者:User

標籤: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嘗試 串連資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.