今天在用junit测试mybits程序是遇到一个问题,报错为: org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLException: The serv ......
今天在用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。关于其它有关服务器时区与数据库的知识点,大家可以自己搜索了解,这里给大家推荐一篇文章
那么怎么处理呢,在全局配置文件中找到:
<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" />
问题得到解决。
在下也是菜鸟一名,在这里是将学习过程中发现的问题,解决问题的方法分享出来,可能有不足之处请路过的大佬不吝赐教,小的将不胜感激。