iT邦幫忙

1

Java - 使用JDBC連接MySql時出現的報錯

閱讀時間: 1分鐘

相信大家在使用JDBC連接MySql時都有可能出現各種問題,
現在就為大家解決其中一個可能會遇到的問題。

報錯的訊息:

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

原因:
輸入中文字型時會出現以上錯誤訊息

解決方法:
需要修改文件:application.properties
位置:src/main/resources/application.properties

加入語法: useUnicode=true&characterEncoding=UTF-8

For MySQL Connection

spring.datasource.url=jdbc:mysql://localhost:3306/sys?serverTimezone=UTC&useSSL=false
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.http.encoding.force=true

For MySQL Connection

spring.datasource.url=jdbc:mysql://localhost:3306/sys?serverTimezone=UTC&useSSL=false& useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.http.encoding.force=true

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
iT邦新手 4 級 ‧ 2020-09-01 16:54:16

感謝:))
/images/emoticon/emoticon12.gif

能夠幫你解決到問題就太好了 ^_^

我要留言

立即登入留言