Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > ResultSet.getTimeStamp()

Reply
Thread Tools

ResultSet.getTimeStamp()

 
 
RAMK
Guest
Posts: n/a
 
      03-22-2005
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...
In addition to this, shortly this is my problem: 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. 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. My assumption is that
there exists some default timezone conversion by JDBC driver while
reading the date from the database.
Please clarify...

Much appreciated,
Ramesh

 
Reply With Quote
 
 
 
 
P.Hill
Guest
Posts: n/a
 
      03-22-2005
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
 
Reply With Quote
 
 
 
 
Lee Fesperman
Guest
Posts: n/a
 
      03-22-2005
RAMK wrote:
>
> .... My assumption is that
> there exists some default timezone conversion by JDBC driver while
> reading the date from the database.
> Please clarify...


Yes, but that is entirely up to the JDBC driver. SQL92 supports Time/Timestamp both with
and without a timezone specification. You could assume that the ones without a tz
specification would use the timezone of the server on the server and would convert to
the client's tz when transferring without conversion. For instance, converting the value
to string on the server would get the server one. The getTimestamp() method with a
Calender object is intended to force a specific tz rather than the current default.
However, there are no guarantees in any case; check the docs for your driver/backend or
test.

BTW, the support for SQL92 Time/Timestamp with Timezone seems to be rare.

--
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
================================================== ============
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57