I\'m using Java 8 with Spring\'s JdbcTemplate
and Oracle 12.1,
I want to update record and get the exact time record was updated
jdbcTempla
You're right that passing new Date()
would store the server time rather than the DB time.
To store the DB time you can set your timestamp to the DB system timestamp systimestamp
then you could run a query to retrieve that row and its updated timestamp.
If you want to update the row and get the updated timestamp in a single execution then you could do the following using RETURNING INTO
where TimestampUpdated
is your column name:
Connection con = ...;
String sql = "UPDATE TableName SET , TimestampUpdated = systimestamp RETURNING TimestampUpdated INTO ?";
CallableStatement statement = con.prepareCall(sql);
statement.registerOutParameter(1, Types.TIMESTAMP);
int updateCount = statement.executeUpdate();
Timestamp timestampUpdated = statement.getInt(1);
System.out.println("Timestamp Updated = " + timestampUpdated);
Here is a related link doing this with JdbcTemplate