Mysql is saving date 1 day earlier date that provided from input from java application

江枫思渺然 提交于 2019-12-24 04:41:08

问题


I am using following specifications in my current project (production)

  1. OS: CentOS 7
  2. Database: MySql
  3. Java 8
  4. Hibernate
  5. tomcat server 8

The database is in separate server than application server but both are in same LAN.

Datatype in mysql table is: date for storing date only and datetime for saving date along with time.

The problem is mysql saved every date 1 day earlier than the date provided from applcation. I have tried the following till now but still no luck:

  1. I have set timezone for both application and database server as Asia/Dhaka and checked this from my java application too.
  2. I have also set timezone in tomcat server (setenv.sh) file.
  3. I have also checked the generated sql from hibernate by TRACE in log4j properties file where the date is also same as input date.

What am I missing? Can anybody suggest?


回答1:


Thanks to all for sharing your experience regarding the issue.

At last, I solved it by changing the serverTimezone attribute of mysql connection string in dispatcher-servlet of my java web application.

<property name="url" value="jdbc:mysql://x.x.x..x:3306/dbname?characterEncoding=utf-8&amp;useSSL=false&amp;serverTimezone=Asia/Dhaka" /> 



回答2:


Maybe you can try changing the serverTimezone:

serverTimezone=GMT%2B8


来源:https://stackoverflow.com/questions/52473215/mysql-is-saving-date-1-day-earlier-date-that-provided-from-input-from-java-appli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!