In my db table I have a column c_dob of Type date
For my controller Request class, I use the above field like this :
import java.sql.Timestamp;
public class UpdateUserProfileRequest {
private Timestamp dob;
public Timestamp getDob() {
return dob;
}
public void setDob(Timestamp dob) {
this.dob = dob;
}
}
Problems :
What happens is when I have the value
1979-06-30passed as a request json value, in the controller class, the request class logs the value as1979-06-30 02:00:00.0(hour part is added and given a value on its own)Second, for setting the dob the following code I am using :
Map<String, Object> outMap = proc.execute(inParams); profile.setDob((Date) outMap.get("out_dob") != null ? new Timestamp(((Date) outMap.get("out_dob")).getTime()) : null);
And what happens here is that 1979-06-30 02:00:00.0 is changed to 1979-06-30 01:00:00.0 which causes logical problem.
So, is there any reason or any solution for this behavior?
Edit : Database is MySql
DATE?java.sql.Timestampis terribly flawed, and was supplanted years ago by the modern java.time classes.java.sql.Timeis also one of the terrible legacy classes. You need to learn about the classes in the java.time package, defined in JSR 310. Search Stack Overflow to learn more. There are many hundreds of existing Questions and Answers.javax.sqlclasses in your model. Instead use the newerjava.timeones. AlsoTimestampis both a data and time hence the time will be added. If you really want to stick with the javax.sql stuff (which I hardly recommend) useDatewhich is only a data without time.