一、驅動下載下傳
下載下傳位址:https://downloads.mysql.com/archives/c-j/

說明:需要根據需要下載下傳對應版本的驅動(我使用的MySQL5.7.20,下載下傳的驅動版本為5.1.48)
二、具體配置及執行結果
Database URL:
jdbc:mysql://ip:3306/yytest?allowMultiQueries=true&characterEncoding=UTF-8
對應資料庫中資料為下圖圈出來的資料(後面2條是新增的,屬于在執行查詢時不存在的資料)
三、遇到問題
1、Cannot create PoolableConnectionFactory (Unknown database ‘yytest&characterencoding=utf-8’)
錯誤資訊:
Cannot create PoolableConnectionFactory (Unknown database
‘yytest&characterencoding=utf-8’)
原因分析:将資料庫URL中的?寫成了&引起。
解決方法:按照錯誤提示将
'yytest&characterencoding=utf-8'
修改為’
yytest?characterencoding=utf-8'
就OK了。
2、Response message: java.sql.SQLException: Cannot create PoolableConnectionFactory
錯誤資訊:
Response message: java.sql.SQLException: Cannot create
PoolableConnectionFactory (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.)
原因分析:驅動版本不對
解決方法:将使用的最新版的驅動
mysql-connector-java-8.0.20.jar
換成驅動
mysql-connector-java-5.1.48.jar
和
mysql-connector-java-5.1.48-bin.jar
,就ok了。
具體下載下傳頁面:
四、“allowMultiQueries=true”的作用
MySQL連接配接資料庫時,添加語句:
“allowMultiQueries=true”
的作用:可以使得sql語句中有多個insert或者update語句。如更新已有資料: