Reputation: 5659
I am hitting the Database and getting a table data using Spring's jdbcTemplate which gives me a list of Map of each record like below:
List<Map<String, Object>> tableDataMap = this.jdbcTemplate.queryForList(this.sql, new Object[] { isModel });
Now if I see the first map for LST_UPDTD_TIME column value it is:-
LST_UPDTD_TIME=2015-09-08 11:24:45.0
But if I try to cast it from Object to java.sql.Timestamp like below:-
(java.sql.Timestamp) mapRow.get("LST_UPDTD_TIME")
I am getting output as:-
2015-09-08 00:00:00.0
Can anyone tell me why time is getting lost while casting from Object to java.sql.Timestamp and how to solve this.
If I execute : System.out.println(mapRow.get("LST_UPDTD_TIME").getClass());
Getting output as: class java.sql.Timestamp
Also column type in database is TIMESTAMP(6).
Thanks
Upvotes: 2
Views: 612
Reputation: 109613
The cause is the involvement of java.sql.Date
which is a wrapper for java.util.Date
, sibling of Timestamp. That SQL Date clears the time part, and is intended for SQL DATE.
If the driver thinks to yield a java.sql.Date
, then the database probably has defined DATE for the column - a problem. Somehow that does not fit your error description though.
Check the .getClass()
anyway.
Upvotes: 0