问题
I am using following specifications in my current project (production)
- OS: CentOS 7
- Database: MySql
- Java 8
- Hibernate
- 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:
- I have set timezone for both application and database server as Asia/Dhaka and checked this from my java application too.
- I have also set timezone in tomcat server (setenv.sh) file.
- 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&useSSL=false&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