John Topley's Knowledgebase

Retaining The Time Component When Assigning A SQL Date To A Java Date

Wednesday, 05 May 2004

When retrieving a java.sql.Date object—representing the contents of a database date column—using the JDBC ResultSet's getDate method, assigning the retrieved value to a java.util.Date object causes the time component to be lost i.e. it gets set to 00:00:00.

The code given below shows how to retain the time component. “rset” is a variable of type java.sql.ResultSet.

java.util.Date dateUpdated
  = new Date(rset.getTimestamp("DateUpdated").getTime());

top | index | previous | next | comments ()

home | archive | kb | media | about | contact | accessibility
Copyright © 2003 - 2005 John Topley. Made with CityDesk.