java.sql.Date only store date data does not store time data
//Loss of time data
preparedstatement.setdate (1, new Java.sql.Date (Date.gettime ()));
//can handle
preparedstatement.settimestamp (1, New Java.sql.Timestamp (New Java.util.Date () . GetTime ()));
//Want to get complete data, including date and time, so
java.util.Date d = resultset.gettimestamp (1);
//This is a more appropriate process to avoid some potential timestamp problems
java.util.Date d = new Java.util.Date ( Resultset.gettimestamp (1). GetTime ());
this way:
can receive the Java.util.Date type when storing to the database Then use the GetTime () method to get a long value representing that date object, and then construct a timestamp object with this long value into the database.
from the storage database, you can get timestamp use his gettime () method to get a long value, The Long value is then used to construct a Java.util.Date object so that the date object can be manipulated. For example, New Simpletimeformat ("Yyyyy-mm-dd HH:mm:ss"). Format () and so on