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

问题获得解决。编码

 

在下也是菜鸟一名,在这里是将学习过程当中发现的问题,解决问题的方法分享出来,可能有不足之处请路过的大佬不吝赐教,小的将不胜感激。

相关文章
相关标签/搜索