org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents mor


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

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...

 

 

 

的時區(地理中的時區),是需要自己設置的,一般的UTC為世間標准時間,不屬於任何時區,

UTC時區默認比北京時間晚8個小時,中國時區為CST。關於其它有關服務器時區與數據庫的知識點,大家可以自己搜索了解,這里給大家推薦一篇文章

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

那么怎么處理呢,在全局配置文件中找到:

 

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

 

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

添加后為:

 <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" />

問題得到解決。

 

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manu org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.NumberFormatException: For input string: "W%" ### Cause: java.lang.NumberFormatException: For input s [mybatis]org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. 異常解決 org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent succ org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure 異常:org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解決java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone 解決java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM