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?
This seems to be an incorrect interpretation of the JDBC API documentation (and unfortunately the
javax.sql.rowset
has more of those incorrect interpretations).By default a JDBC driver needs to store or retrieve a time or timestamp as if the time stored in the database is in the current timezone of the JVM. As this isn't always what you want, the API provides methods to provide a
Calendar
object, which you need to use to derive the actual timezone to use (I don't know why they didn't usejava.util.TimeZone
instead).This is specified in PreparedStatement.setTimeStamp:
The method
getTimestamp
inResultSet
follows (or should follow) these same rules.So if a database stores time '11:20' and your local timezone is CET (UTC+1), then the retrieved time is 10:20 UTC (11:20 CET). However if I provide a
Calendar
in GMT, the returned time should be 11:20 UTC (12:20 CET).