I have a Timestamp
column in my source database which is getting read in my java program as a String
.
String dateWithNano = "2011-10-02 18:48:05.123456";
I have to set the same Timestamp
in the destination database column.
I am doing the following for the same:
java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSSSSS");
if(dateWithNano== null || dateWithNano.equalsIgnoreCase("")){
ps.setTimestamp(1,null);
}else{
java.util.Date parsedDate = format1.parse(item.getUPDATED_TS());
ps.setTimestamp(1, new java.sql.Timestamp(parsedDate.getTime()));
}
But the nanosecond
value in the destination database is getting compromised. Its not same as 2011-10-02 18:48:05.123456
What is the correct way for this so that the same nanosecond value persists across source and destination database ?