Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 756
sarwar026 Avatar asked Oct 28 '22 04:10

sarwar026


1 Answers

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" /> 
like image 175
sarwar026 Avatar answered Nov 15 '22 05:11

sarwar026