解決Mybatis的serverTimezone時區(qū)出現(xiàn)問題
Mybatis serverTimezone時區(qū)出現(xiàn)問題
錯誤信息
我們可以定位錯誤信息The server time zone value 'Öйú±ê׼ʱ¼ä' is,
則說明了是serverTimezone時區(qū)的問題
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: 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.
### The error may exist in com/chun/dao/UserMapper.xml
### The error may involve com.chun.dao.UserMapper.getUserList
### The error occurred while executing a query
### Cause: java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time
出現(xiàn)原因
因為MySQL版本號是8.0以上,需要設置serverTimezone,useSSL等參數(shù)
解決
在mybatis-config.xml文件中的property name="url"在后面添加
&serverTimezone=Asia/Shanghai" //注意Shanghai是開頭大寫 或者 &serverTimezone=GMT%2B8
<property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"/>
Mybatis 插件碰到的時區(qū)問題及用法
連接數(shù)據(jù)庫mysql -hlocalhost -uroot -p,回車,輸入密碼,回車,
show variables like'%time_zone'; (注意不要漏掉后面的分號),回車
設置時區(qū) set time_zone = '+8:00';
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
基于Mybatis實現(xiàn)動態(tài)數(shù)據(jù)源切換的示例代碼
在當今的互聯(lián)網應用中,微服務大行其道,隨著業(yè)務的發(fā)展和擴展,單一的數(shù)據(jù)庫無法滿足日益增長的數(shù)據(jù)需求,本文將基于 JDK17 + Spring Boot 3 和 MyBatis 框架實現(xiàn)動態(tài)切換數(shù)據(jù)源功能,需要的朋友可以參考下2024-09-09springboot整合log4j的踩坑實戰(zhàn)記錄
log日志的重要性不言而喻,所以我們需要在系統(tǒng)內根據(jù)實際的業(yè)務進行日志的整合,下面這篇文章主要給大家介紹了關于springboot整合log4j的踩坑實戰(zhàn)記錄,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下2022-04-04解決Spring Cloud feign GET請求無法用實體傳參的問題
這篇文章主要介紹了解決Spring Cloud feign GET請求無法用實體傳參的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-01-01SpringMVC4.3?HandlerExceptionResolver異常處理源碼解析
這篇文章主要為大家介紹了SpringMVC4.3?HandlerExceptionResolver異常處理源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪<BR>2023-09-09