org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLE

今天在用junit測試mybits程序是遇到一個問題,報錯爲:java

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/po/User.xml
### The error may involve first.searchUserById
### The error occurred while executing a query
### 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.
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
    at com.test.TestUser.testSearchUserById(TestUser.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4...

mysql

 

 

 

的時區(地理中的時區),是須要本身設置的,通常的UTC爲世間標準時間,不屬於任什麼時候區,sql

UTC時區默認比北京時間晚8個小時,中國時區爲CST。關於其它有關服務器時區與數據庫的知識點,你們能夠本身搜索瞭解,這裏給你們推薦一篇文章數據庫

https://blog.csdn.net/vae1314chuanchen/article/details/81838476apache

那麼怎麼處理呢,在全局配置文件中找到:服務器

 

<property name="url" value="jdbc:mysql://服務器地址:端口號/數據庫名 />

 

在數據庫名稱後面加入:serverTimezone=UTC&amp;useSSL=false  ,若是,你的url後面還有其它參數則應該加入:serverTimezone=UTC&amp;useSSL=false&amp;session

添加後爲:學習

 <property name="url" value="jdbc:mysql://服務器地址:端口號/數據庫名?serverTimezone=UTC&amp;useSSL=false&amp;useUnicode=true"/>

若是後面還有參數(如設置編碼)則爲:測試

 <property name="url" value="jdbc:mysql://服務器地址:端口號/數據庫名?serverTimezone=UTC&amp;useSSL=false&amp;useUnicode=true&amp;characterEncoding=utf-8" />

問題獲得解決。編碼

 

在下也是菜鳥一名,在這裏是將學習過程當中發現的問題,解決問題的方法分享出來,可能有不足之處請路過的大佬不吝賜教,小的將不勝感激。

相關文章
相關標籤/搜索