I have created a date object and formatted it as follows :
Date dt = new java.util.Date();
SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String currentTime = sdf.format(dt);
This formatted date will be used to update a field as date time in the database as follows.
String sql = "update userdetails set lastupdatedOn = '"+currentTime+"' where name ='userA'";
getJdbcTemplate().execute(sql);
The issue I am facing is that the date is always a couple of minutes behind the system time.
Edit : The code I have written here is just a sample to demonstrate what I wanted to accomplish. I cannot use CURRENT_TIMESTAMP or getDate() since it would fetch the time from DB sever system. I should be setting the time using java code instead. Though the time fetched by that manner is a couple of minutes behind the system time(the system in which the tomcat server is running) which is the issue I am facing.