I'm talking about this interface method:
The most commonly used implementation being the one in cachedrowset:
You will notice that the implementation does two very weird things:
1) it modifies the calendar passed as argument, even though there is also a return value
2) it extracts all the time information from SQL, except for the milliseconds, which come from the calendar passed as argument.
The interface description is rather unclear, but assuming the implementation is correct - What is the point of this method? I can understand a method that would take a calendar to extract just the timezone, without modifying it. But taking a calendar, modifying it, and extracting not only the zone but also the milliseconds...
Does anyone have any insight as to the history/design/reasoning behind this API?
SQL databases store the date and time value for timestamps in the form of year, month, day, hour min, sec etc. The instance in time these values specify depends on the timezone in which they are interpreted (e.g. 2014. january 1. 15:00:00 is not at the same time in Europe than in the USA). The timezone may or may not be part of the timestamp, depending on the column's type.
The Java
java.sql.Timestampandjava.util.Dateclasses represent an instance of time regardless of the time zone (or rather in a fixed, UTC timezone).If the column in the SQL database does not store the timezone info along with the date+time, in order to create a Java
DateorTimeStampobject from such a timestamp requires a timezone so it can point to a specific instance in time (in the reference UTC timezone).The
ResultSet.getTimestamp()method in question can be used to get an SQL timestamp data and convert it to a JavaTimestampinstance using the timezone info set in the parameterCalendarobject.