JDBC访问MySql异常

Exception in thread "main" 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.

原因分析

数据库安装时默认为英语,0:00时区

Windows系统中,XP的时区是GMT,而Win7的时区是UTC。

mysql返回的时间会比实际时间要早8小时。

解决方案,以下任选一种即可解决问题:

1、配置JDBC连接参数

在url连接字符串后面加上?serverTimezone=UTC

例如:
jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&serverTimezone=UTC

jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF8&serverTimezone=UTC

学点新知识:

UTC,世界均衡时间

GMT,格林尼治时间

北京时间(东八区),GMT+8,url中表示为:&serverTimezone=GMT%2B8

jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&serverTimezone=GMT%2B8

我们一般认为GMT和UTC是一样的,都与英国伦敦的本地时相同。

2、修改MySQL数据库配置,需要DBA的root权限

使用root用户登录mysql

--查看时区值
show variables like '%time_zone%';

--设置为东八区(北京时间)
set global time_zone='+8:00';

3、有人说,使用低版本的MySQL jdbc驱动,5.1.47不会存在时区的问题,的确如此。

MySql数据库时区异常,java.sql.SQLException: The server time zone value '?й???׼ʱ?' is unrecognized or represents more than one time zone.的更多相关文章

  1. 连接mysql数据库报错java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized...解决方法

    今天连接mysql数据库报错如下: java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or r ...

  2. mysql报错:java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.

    mybatis链接mysql,启动服务报错: java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecogni ...

  3. Eclipse使用jdbc连接MySql数据库报:java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

    在使用eclipse连接mysql数据库时报异常: java.sql.SQLException: Access denied for user 'root'@'localhost' (using pa ...

  4. ssm框架下 数据库连接异常 java.sql.SQLException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more

    1.错误截图 2.修改操作 我是在框架的中连接的数据库,如果在类中把    &换成& 修改前代码 <property value="com.mysql.jdbc.Dri ...

  5. java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ 解决方案

    //第一个异常 Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysq ...

  6. 【JDBC】java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.

    在使用阿里的druid 时,报了一个异常java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized ...

  7. 解决java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone

    使用spring boot整合MySQL时一直报 java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecog ...

  8. MySQL连接数据库报时区错误:java.sql.SQLException: The server time zone value

    连接MySQL数据库时报以下时区错误信息: java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized ...

  9. 【MySQL】java.sql.SQLException: The server time zone value

    错误:Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: The se ...

随机推荐

  1. 创建一个dynamics 365 CRM online plugin (八) - 使用Shared Variables 在plugins 之前传递data

    CRM 可以实现plugin之前的值传递. 我们可以使用SharedVariables 把值在plugin之间传递 实现plugins之间的传递非常简单,我们只需要用key value pair来配对 ...

  2. idea调试代码跟踪到tomcat代码里面

    在POM.xml文件里面加上如下代码即可: <dependency> <groupId>org.apache.tomcat</groupId> <artifa ...

  3. QQ群成员发言次数统计(词云制作)

    所用数据来自于之前的一篇博客: <QQ群成员发言次数统计(正则表达式版)> 链接:http://www.cnblogs.com/liyongzhao/p/3324026.html 1.首先 ...

  4. windows下使用caffe测试mnist数据集

    在win10机子上装了caffe,感谢大神们的帖子,要入坑caffe-windows的朋友们看这里,还有这里,安装下来基本没什么问题. 好了,本博文写一下使用caffe测试mnist数据集的步骤. 1 ...

  5. Tcl 编译成tbc文件

    工具:tclpro1.4 下载地址:https://www.tcl.tk/software/tclpro/eval/1.4.html 永久license:  Version 1.4: 1094-320 ...

  6. DApp demo之pet-shop

    注意: 这里使用的truffle版本为4.1.4,貌似使用高版本在truffle test时候会出问题,提示 truffle/Assert.sol is not found等错误 使用Truffle ...

  7. Windows下安装配置Flutter

    Flutter是谷歌的移动UI框架,可以快速在iOS和Android上构建高质量的原生用户界面. Flutter可以与现有的代码一起工作.在全世界,Flutter正在被越来越多的开发者和组织使用,并且 ...

  8. 2016-08-15T16:00:00.000Z 格式转换成yyyy-MM-dd HH:mm:ss格式

    public static String UTCStringtODefaultString(String UTCString) { try { if (CommonUtils.notNullAndEm ...

  9. js判断数组里是否有重复元素的方法

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/longzhoufeng/article/details/78840974 第一种方法:但是下面的这种 ...

  10. linux下查看已安装的软件与卸载

    转自:https://blog.csdn.net/qq_22075041/article/details/78855849 因为linux安装软件的方式比较多,所以没有一个通用的办法能查到某些软件是否 ...