欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

对于使用JDBC连接mysql数据时The server time zone value '¤¤°ê¼Ð·Ç®É¶¡'...的异常问题解决。

程序员文章站 2022-10-23 21:25:19
在使用JDBC连接mysql数据库的时候发生SQLException '¤¤°ê¼Ð·Ç®É¶¡'的异常情况! ......

相信很多小伙伴和我一样遇到了这类问题,在使用jdbc连接mysql数据库的时候发生sqlexception如下所示的异常情况!

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 com.mysql.cj.jdbc.exceptions.sqlerror.createsqlexception(sqlerror.java:129)
    at com.mysql.cj.jdbc.exceptions.sqlerror.createsqlexception(sqlerror.java:97)
    at com.mysql.cj.jdbc.exceptions.sqlerror.createsqlexception(sqlerror.java:89)
    at com.mysql.cj.jdbc.exceptions.sqlerror.createsqlexception(sqlerror.java:63)
    at com.mysql.cj.jdbc.exceptions.sqlerror.createsqlexception(sqlerror.java:73)
    at com.mysql.cj.jdbc.exceptions.sqlexceptionsmapping.translateexception(sqlexceptionsmapping.java:76)
    at com.mysql.cj.jdbc.connectionimpl.createnewio(connectionimpl.java:835)
    at com.mysql.cj.jdbc.connectionimpl.<init>(connectionimpl.java:455)
    at com.mysql.cj.jdbc.connectionimpl.getinstance(connectionimpl.java:240)
    at com.mysql.cj.jdbc.nonregisteringdriver.connect(nonregisteringdriver.java:199)
    at java.sql.drivermanager.getconnection(unknown source)
    at java.sql.drivermanager.getconnection(unknown source)
    at com.ast.service.impl.vboxdataserviceimpl.insertall(vboxdataserviceimpl.java:34)
    at com.ast.controller.thread_send.run(thread_send.java:85)
caused by: com.mysql.cj.exceptions.invalidconnectionattributeexception: 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 sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method)
    at sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source)
    at sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source)
    at java.lang.reflect.constructor.newinstance(unknown source)
    at com.mysql.cj.exceptions.exceptionfactory.createexception(exceptionfactory.java:61)
    at com.mysql.cj.exceptions.exceptionfactory.createexception(exceptionfactory.java:85)
    at com.mysql.cj.util.timeutil.getcanonicaltimezone(timeutil.java:132)
    at com.mysql.cj.protocol.a.nativeprotocol.configuretimezone(nativeprotocol.java:2241)
    at com.mysql.cj.protocol.a.nativeprotocol.initserversession(nativeprotocol.java:2265)
    at com.mysql.cj.jdbc.connectionimpl.initializepropsfromserver(connectionimpl.java:1319)
    at com.mysql.cj.jdbc.connectionimpl.connectonetryonly(connectionimpl.java:966)
    at com.mysql.cj.jdbc.connectionimpl.createnewio(connectionimpl.java:825)
    ... 7 more

这其实是由于在安装的时候没有选择使用位置,mysql默认使用美国时间,所以得改成我们东八区的时间。

所以应该怎么做呢?

首先网上有很多方法是更改数据库中的 time_zone,如下图:

对于使用JDBC连接mysql数据时The server time zone value '¤¤°ê¼Ð·Ç®É¶¡'...的异常问题解决。

这个方法只能是解决这一次问题,重启之后依然会报错,还需要再次更改。

最好的方法就是在jdbc配置中添加?servertimezone=utc到末尾。

如下图所示:

对于使用JDBC连接mysql数据时The server time zone value '¤¤°ê¼Ð·Ç®É¶¡'...的异常问题解决。