jdbc插入或查询数据库时间总是比实际时间少8小时原因
mysql插入数据库的时间总是有问题,比实际时间要早8小时。检查是jdbc连接的url中配置的时区有问题,原先是
jdbc.url=jdbc:mysql://47.**.**.**:3306/yeeya?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=UTC
尝试了GMT、GMT8、UTC+8,UTC0800等可能的参数均报错。后来在mysql文档中发现可用的时区都在/usr/share/zoneinfo目录下,ll下发现可用的时区信息如下
lewis@lewis-dzwww:/usr/share/zoneinfo$ ll
总用量 308
drwxr-xr-x 21 root root 4096 5月 27 12:54 ./
drwxr-xr-x 334 root root 12288 6月 21 15:11 ../
drwxr-xr-x 2 root root 4096 5月 27 12:56 Africa/
drwxr-xr-x 6 root root 4096 5月 27 12:56 America/
drwxr-xr-x 2 root root 4096 5月 27 12:56 Antarctica/
drwxr-xr-x 2 root root 4096 5月 27 12:56 Arctic/
drwxr-xr-x 2 root root 4096 5月 27 12:56 Asia/
drwxr-xr-x 2 root root 4096 5月 27 12:56 Atlantic/
drwxr-xr-x 2 root root 4096 5月 27 12:56 Australia/
drwxr-xr-x 2 root root 4096 5月 27 12:56 Brazil/
drwxr-xr-x 2 root root 4096 5月 27 12:56 Canada/
-rw-r--r-- 1 root root 2102 4月 21 02:09 CET
drwxr-xr-x 2 root root 4096 5月 27 12:56 Chile/
-rw-r--r-- 1 root root 2294 4月 21 02:09 CST6CDT
-rw-r--r-- 1 root root 2437 4月 21 02:09 Cuba
-rw-r--r-- 1 root root 1876 4月 21 02:09 EET
-rw-r--r-- 1 root root 1972 4月 21 02:09 Egypt
-rw-r--r-- 1 root root 3559 4月 21 02:09 Eire
-rw-r--r-- 1 root root 127 4月 21 02:09 EST
-rw-r--r-- 1 root root 2294 4月 21 02:09 EST5EDT
drwxr-xr-x 2 root root 4096 5月 27 12:56 Etc/
drwxr-xr-x 2 root root 4096 5月 27 12:56 Europe/
-rw-r--r-- 1 root root 264 4月 21 02:09 Factory
-rw-r--r-- 1 root root 3687 4月 21 02:09 GB
lrwxrwxrwx 1 root root 2 5月 27 09:07 GB-Eire -> GB
-rw-r--r-- 1 root root 127 4月 21 02:09 GMT
lrwxrwxrwx 1 root root 3 5月 27 09:07 GMT0 -> GMT
lrwxrwxrwx 1 root root 3 5月 27 09:07 GMT-0 -> GMT
lrwxrwxrwx 1 root root 3 5月 27 09:07 GMT+0 -> GMT
lrwxrwxrwx 1 root root 3 5月 27 09:07 Greenwich -> GMT
-rw-r--r-- 1 root root 1189 4月 21 02:09 Hongkong
-rw-r--r-- 1 root root 128 4月 21 02:09 HST
-rw-r--r-- 1 root root 1190 4月 21 02:09 Iceland
drwxr-xr-x 2 root root 4096 5月 27 12:56 Indian/
-rw-r--r-- 1 root root 1678 4月 21 02:09 Iran
-rw-r--r-- 1 root root 4475 2月 24 17:01 iso3166.tab
-rw-r--r-- 1 root root 2265 4月 21 02:09 Israel
-rw-r--r-- 1 root root 507 4月 21 02:09 Jamaica
-rw-r--r-- 1 root root 355 4月 21 02:09 Japan
-rw-r--r-- 1 root root 237 4月 21 02:09 Kwajalein
-rw-r--r-- 1 root root 10384 2月 22 23:58 leap-seconds.list
-rw-r--r-- 1 root root 655 4月 21 02:09 Libya
lrwxrwxrwx 1 root root 14 5月 27 09:07 localtime -> /etc/localtime
-rw-r--r-- 1 root root 2102 4月 21 02:09 MET
drwxr-xr-x 2 root root 4096 5月 27 12:56 Mexico/
-rw-r--r-- 1 root root 127 4月 21 02:09 MST
-rw-r--r-- 1 root root 2294 4月 21 02:09 MST7MDT
-rw-r--r-- 1 root root 2453 4月 21 02:09 Navajo
-rw-r--r-- 1 root root 2460 4月 21 02:09 NZ
-rw-r--r-- 1 root root 2057 4月 21 02:09 NZ-CHAT
drwxr-xr-x 2 root root 4096 5月 27 12:56 Pacific/
-rw-r--r-- 1 root root 2705 4月 21 02:09 Poland
-rw-r--r-- 1 root root 3453 4月 21 02:09 Portugal
drwxr-xr-x 19 root root 4096 5月 27 12:56 posix/
-rw-r--r-- 1 root root 3545 4月 21 02:09 posixrules
-rw-r--r-- 1 root root 414 4月 21 02:09 PRC
-rw-r--r-- 1 root root 2294 4月 21 02:09 PST8PDT
drwxr-xr-x 19 root root 4096 5月 27 12:56 right/
-rw-r--r-- 1 root root 800 4月 21 02:09 ROC
-rw-r--r-- 1 root root 571 4月 21 02:09 ROK
-rw-r--r-- 1 root root 428 4月 21 02:09 Singapore
drwxr-xr-x 2 root root 4096 5月 27 12:56 SystemV/
-rw-r--r-- 1 root root 2747 4月 21 02:09 Turkey
-rw-r--r-- 1 root root 127 4月 21 02:09 UCT
lrwxrwxrwx 1 root root 4 5月 27 09:07 Universal -> Zulu
drwxr-xr-x 2 root root 4096 5月 27 12:56 US/
lrwxrwxrwx 1 root root 4 5月 27 09:07 UTC -> Zulu
-rw-r--r-- 1 root root 1873 4月 21 02:09 WET
-rw-r--r-- 1 root root 1528 4月 21 02:09 W-SU
-rw-r--r-- 1 root root 17533 4月 13 16:01 zone1970.tab
-rw-r--r-- 1 root root 19014 4月 13 16:01 zone.tab
-rw-r--r-- 1 root root 127 4月 21 02:09 Zulu
为解决此问题,可以选择东8区的Hongkong、Asia/Shanghai或者Asia/Hongkong作为参数,修改后url为
jdbc.url=jdbc:mysql://47.**.**.**:3306/yeeya?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=Asia/Shanghai
jdbc插入或查询数据库时间总是比实际时间少8小时原因的更多相关文章
- jmeter 性能测试 JDBC Request (查询数据库获取数据库数据) 的使用
JDBC Request 这个Sampler可以向数据库发送一个jdbc请求(sql语句),并获取返回的数据库数据进行操作.它经常需要和JDBC Connection Configuration配置原 ...
- jmeter JDBC Request (查询数据库获取数据库数据) 的使用
JDBC Request 这个Sampler可以向数据库发送一个jdbc请求(sql语句),并获取返回的数据库数据进行操作.它经常需要和JDBC Connection Configuration配置原 ...
- 转jmeter 性能测试 JDBC Request (查询数据库获取数据库数据) 的使用
JDBC Request 这个Sampler可以向数据库发送一个jdbc请求(sql语句),并获取返回的数据库数据进行操作.它经常需要和JDBC Connection Configuration配置原 ...
- mysql数据库建表分类字段--尽量少用字符串--原因探索
虽然一直都知道,类型 之类的字段 直接用字符窜会很方便,不过最好还是不要用字符串:但是也不是特别清楚为什么不要用,时间久了 就忍不住用一下字符窜试试,这一试 还挺好用的,吓得我 感觉探究了一下 为什么 ...
- Hibernate框架的基本搭建(一个小的java project的测试向数据库中插入和查询数据的功能)
Hibernate介绍:Hibernate是一种“对象-关系型数据映射组件”,它使用映射文件将对象(object)与关系型数据(Relational)相关联,在Hibernate中映射文件通常以&qu ...
- Java 通过JDBC查询数据库表结构(字段名称,类型,长度等)
Java 通过JDBC查询数据库表结构(字段名称,类型,长度等) 发布者:唛唛家的豆子 时间:2012-11-20 17:54:02 Java 通过JDBC查询数据库表结构(字段名称,类型,长 ...
- 用JDBC查询数据库
JDBC API的核心组件:1.DriverManager类:用语跟踪可用的JDBC驱动程序并产生数据库连接. 2.Connection接口:用于取得数据库信息.生成数据库语句,并管理数据库事务. 3 ...
- java序列化对象 插入、查询、更新到数据库
java序列化对象 插入.查询.更新到数据库 : 实现代码例如以下: import java.io.ByteArrayInputStream; import java.io.ByteArrayOutp ...
- 关于mysql查询数据库时间和系统时间差
1. MySQL数据库表中有两个时间的字段,需要计算他们的时间差: (1)datediff函数来表示时间差. 基本语法: DATEDIFF(datepart,startdate,enddate) 说明 ...
随机推荐
- 在CentOS7系统安装与配置RabbitMQ
在CentOS7系统安装与配置RabbitMQ 远程访问需要开放端口 https://www.cnblogs.com/heqiuyong/p/10460150.html
- 把rocksdb配置成leveldb
将rocksdb配置成leveldb 1.配置方法 配置方式有三种: 第一种适合进行性能测试对比:是以参数形式在运行db_bench或ycsb-c的时候以参数形式将rocksdb将其配置成leveld ...
- centos6.5-rsync+inotify
一.目的 通过监控192.168.3.10的目录,实现实时同步. 实验环境 centos1 192.168.3.10 centos2 192.168.3.11 二.配置 cen ...
- monkey怎么做APP自动化?
前言: monkey是andriod平台自动化测试的一种手段,通过monkey程序模拟触摸屏幕.滑动,滚屏,按键来对设备进行压力测试,检测程序多久会出现异常第一种:设置好命令,做随机自动化 什么时候可 ...
- centos7-collabora-office(在线文档编辑)
1.wget https://www.collaboraoffice.com/repos/CollaboraOnline/CODE-centos7/repodata/repomd.xml.key &a ...
- 怎样在 CentOS/RHEL 7/6 上安装和配置 Sendmail 服务器
在 CentOS 上,可以通过 mailx 命令 或 sendmail 命令来给因特网发送电子邮件. 关于前者的文章比较多,关于后者的文章比较少. 这里记录了我在 CentOS 7 上安装和配置 se ...
- spring boot & maven 多模块 ---心得
1.前言 有个名字叫 多模块企业级项目 ,其实就是一个父级maven工程里面有着多个子级maven工程的项目 ,甚至在子级maven 里面还有多个子级maven, 这用到了 maven多模块开发的使 ...
- Go语言系列之函数
函数是组织好的.可重复使用的.用于执行指定任务的代码块.本文介绍了Go语言中函数的相关内容. 函数 Go语言中支持函数.匿名函数和闭包,并且函数在Go语言中属于"一等公民". 函数 ...
- SpringCloud的Config应用
一.简介 ***应用程序先注册到注册中心,在注册中心根据guli-config服务的名字找到配置中心,然后在配置中心根据配置从github加载基本配置. 二.配置中心(服务端,可以部署集群) 1.依赖 ...
- vue3.0+vue-cli3.0项目搭建
因为需要兼容其他vue2.0的项目,所以先卸载vue-cli,再全局安装桥接工具 卸载vue-cli2.0 npm uninstall vue-cli -g 安装vue-cli3.0 npm inst ...