I was having some problem when trying to convert java.util.Date to java.sql.Date. My date parameter passed in was originally a string in this format: 2019-01-31. Then I am trying to convert it to java.util.date using this code:
SimpleDateFormat formatter = new SimpleDateFormat("YYYY-MM-DD");
Date date = null;
try {
date = formatter.parse(this._dDate);
} catch (ParseException e) {
e.printStackTrace();
}
In my SQL statement, I am trying to convert it to java.sql.Date:
buffer.append("SELECT * FROM TABLE1 WHERE LAST_LOGIN_DT < ");
buffer.append("TO_DATE('" + new java.sql.Date(date.getTime()) + "','YYYY-MM-DD') ");
However, when I printed out the buffer in string, I realized that the date is changed. For instance, the data string I passed in is 2018-01-01, but in the SQL statement it became 2017-12-31. Any ideas?
Thanks!