今天在用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.****.net/vae1314chuanchen/article/details/81838476
那么怎么处理呢,在全局配置文件中找到:
<property name="url" value="jdbc:mysql://服务器地址:端口号/数据库名 />
在数据库名称后面加入:serverTimezone=UTC&useSSL=false ,如果,你的url后面还有其它参数则应该加入:serverTimezone=UTC&useSSL=false&
添加后为:
<property name="url" value="jdbc:mysql://服务器地址:端口号/数据库名?serverTimezone=UTC&useSSL=false&useUnicode=true"/>
如果后面还有参数(如设置编码)则为:
<property name="url" value="jdbc:mysql://服务器地址:端口号/数据库名?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=utf-8" />
问题得到解决。
在下也是菜鸟一名,在这里是将学习过程中发现的问题,解决问题的方法分享出来,可能有不足之处请路过的大佬不吝赐教,小的将不胜感激。