Reputation: 20100
Very weirdly I have found that my JDBI query from my MSSQL database is returning the wrong value for a column of type datetimeoffset(4)
. In the database I have a single row (I removed all other rows for sanity's sake)
ID | Datetimeoffset
------------------------------------
1 | 2016-01-19 22:03:17.0309 -05:00
When I run the below in Java, it prints out 2016-01-17 22:12:50.7357 -05:00
, a very different time than the value in my DB. I'm guessing that somewhere in JDBI it tries to parse the column value into a DATETIMEOFFSET
and gets confused somehow?
Also, when I convert the retrieved value to a java.sql.Timestamp
object and look at the milliseconds value, it is about 2 days prior to the current System.currentTimeMillis()
tblDao.getRow(1)
@RegisterMapper(RowMapper.class)
public interface TblDao {
@SqlQuery("SELET ID, Datetimeoffset FROM tbl WHERE ID = :id")
Row getRow(@Bind("id") Long id);
}
public class RowMapper implements ResultSetMapper<Treatment> {
@Override
public Row map(int index, ResultSet resultSet, StatementContext statementContext ) throws SQLException {
Object timestampObj = resultSet.getObject("CreatedDatetimeoffset");
system.println(timestampObj)
Upvotes: 1
Views: 462
Reputation: 20100
Discovered that this issue was due to the SqlServerDriver. When run on a machine with version 4.0 the proper datetimeoffset
value was returned by query; the wrong value was being returned by a machine with version 3.0.
Upvotes: 1