In JDBC API, I can simply set UTC timezone using the following
For inserting or updating
PreparedStatement myPreparedStatement = ...
myPreparedStatement.setTimestamp( 1, myDateTime, Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ));
For querying
ResultSet rs = ...
rs.next();
rs.getTimestamp( 1, Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ) )
Using Spring JDBC Template, I will need to use something like this to query.
For querying, I don't have any issues because ResultSet is accessible via RowMapper and use the ResultSet to pass on the Calendar instance in UTC. However, for inserting or updating, I only have the following.
NamedParameterJdbcTemplate namedParameterJdbcTemplate = ....
SqlParameterSource parameters = new MapSqlParameterSource().addValue("current_timestamp", myDateTime )
namedParameterJdbcTemplate.update(sql, parameters);
Question
Is there a way to tell the Spring JDBC template to use my specified TimeZone?
I do not prefer to use the TimeZone.setDefault(..) because that's going to affect our legacy modules.