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. VMware Workstation Pro 安装win7系统

    1.准备工作VMware Workstation Pro 虚拟机软件cn_windows_7_enterprise_x64_dvd_x15-70741.iso2.选择典型(推荐)(T) 单选按钮 3. ...

  2. influxdb 全家桶运行

    一个简单的demo,集成了telegraf,influxdb,chronograf,kapacitor,nginx,一张来自官方的参考图 组件集成图 环境准备 使用docker-compose doc ...

  3. fcn训练及预测tgs数据集

    一.背景 kaggle上有这样一个题目,关于盐份预测的语义分割题目.TGS Salt Identification Challenge | Kaggle  https://www.kaggle.com ...

  4. FM与PM信号的表现形式

    角度调制可以写成如下形式: $u(t)=A_c cos(2\pi f_c t + \phi (t) )$ $A_c cos(2\pi f_c t)$是载波,调制信号控制$\phi (t)$. 对于PM ...

  5. version `GLIBC_2.17' not found 解决方法

    1.先查看是哪个函数用的是GLIBC_2.17 root@emb-pc:/home/emb/temp# nm lib61850.so | grep GLIBC_2.17 U clock_gettime ...

  6. python3学习笔记11(函数)

    函数 python提供了许多内建函数,例如print(). 自己创建的函数,叫做用户自定义函数. 定义一个由自己想要功能的函数,以下是简单的规则: 函数代码块以 def 关键词开头,后接函数标识符名称 ...

  7. Group(), Groups(),& Groupdict() 用法

    group() 返回一个或多个匹配的字串.如果只有一个参数,结果只有单个字符串:如果有多个参数,结果是一个元组,元组里每一项对应一个参数.没有参数,group1默认是0(整个匹配串被返回).如果gro ...

  8. Kong配置参考

    kong配置的官网说明:https://docs.konghq.com/1.0.x/configuration/ 1. 配置加载 如果您通过其中一个官方软件包安装了Kong,Kong会附带默认配置文件 ...

  9. 【算法习题】数组中任意2个(3个)数的和为sum的组合

    题1.给定一个int数组,一个数sum,求数组中和为sum的任意2个数的组合 @Test public void test_find2() { int[] arr = { -1, 0, 2, 3, 4 ...

  10. SurfaceView绘图时刷新问题,尝试各种办法无法解决,请教高手

    /** * */ 源码:http://pan.baidu.com/s/1i3FtdZZ 画图时最左面,第一帧总是出现一个黑条,其它的帧没有问题package com.macrosoft.testewa ...