连接MySql出现异常解决:java.sql.SQLException: The server time zone value is unrecognized or represents。
QUESTION:
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.
?
ANSWER:
一:原因
博主在剛開始學(xué)習(xí)SpringBoot的時(shí)候,整合mybatis框架使用MySql數(shù)據(jù)庫配置時(shí)出現(xiàn)以上問題,經(jīng)過查閱資料,找到解決方案,
原因是因?yàn)槭褂昧薓ysql Connector/J 6.x以上的版本,然后就報(bào)了時(shí)區(qū)的錯(cuò)誤
遇到的問題 servertime=UTC導(dǎo)致時(shí)間差8個(gè)小時(shí)
二:解決方法
在配置mysql的URL加上時(shí)區(qū):
serverTimezone=UTC spring.datasource.url=jdbc:mysql://127.0.0.1:3306/springboot?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC雖然上面加上時(shí)區(qū)程序不出錯(cuò)了,但是我們在用java代碼插入到數(shù)據(jù)庫時(shí)間的時(shí)候卻出現(xiàn)了問題。
因?yàn)闀r(shí)區(qū)設(shè)置的問題。
UTC代表的是全球標(biāo)準(zhǔn)時(shí)間 ,但是我們使用的時(shí)間是北京時(shí)區(qū)也就是東八區(qū),領(lǐng)先UTC八個(gè)小時(shí)。
UTC + (+0800) = 本地(北京)時(shí)間。
將時(shí)區(qū)改成中國標(biāo)準(zhǔn)時(shí)間:
serverTimezone=Asia/Shanghai?
總結(jié)
以上是生活随笔為你收集整理的连接MySql出现异常解决:java.sql.SQLException: The server time zone value is unrecognized or represents。的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JSP和HTML中实现字符串换行
- 下一篇: 小白学JAVA,与你们感同身受,JAVA