RAMK wrote:
> Hi,
> I have seen in the java doc of ResultSet.getTimeStamp(String,
> Calendar). But I could not understand the significance of Calendar
> object. Can you please tell me whats the purpose of Calendar object
> here...
Well, it's just what you need!
If we read the JavaDoc, it says:
"This method uses the given calendar to construct an appropriate
millisecond value for the timestamp if the underlying database does not
store timezone information."
--
http://java.sun.com/j2se/1.4.2/docs/...ResultSet.html
and you said:
> I have a date field in
> the database(oracle) like 01-01-1970 10:00. There is no timezone
> information associated with this as it is a normal date type in the
> database.
We need to go from a String "01-01-1970 10:00"
to a millisecond value (10 hours worth of milliseconds since 1/1/1970)
because that is what a java.util.Date uses to represent a datetime.
But 10 in London is not 10 in Tokyo nor the same milliseconds as
10 in San Francisco.
The Calendar provides the missing information. It is the algorithm
for converting from a set of fields to a millisecond value. The
most important part of the algorithm in this case is the timezone.
> Now my JVM is in different timezone. What I require is- this
> date(in the database) to be read as it is into my java code using
> getTimeStamp() without any timezone conversions.
You can set the TZ in the calendar passed to whatever you want,
that is why there is an explicit calendar on this call.
Maybe you'd want the local TZ, or maybe GMT (so you get 10 hours worth
of milliseconds). As you stated you want the second case, so
create a Calendar and set its TZ with something like
cal.setTimeZone( TimeZone.getTimeZone( "GMT" ));
>My assumption is that
> there exists some default timezone conversion by JDBC driver while
> reading the date from the database.
Yes, the default used is the default for the VM as set when the VM
started or overridden via TimeZone.setDefault(), but don't bother with
"moving" the VM, just tell the ResultSet you want something different.
HTH,
-Paul