This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes  java.sql.ResultSet getTimestamp Locale issue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark " java.sql.ResultSet getTimestamp Locale issue" Watch " java.sql.ResultSet getTimestamp Locale issue" New topic
Author

java.sql.ResultSet getTimestamp Locale issue

Mukesh Mittal
Ranch Hand

Joined: Jan 13, 2006
Posts: 31
I am using getTimeStamp(column index, calander function)

In the specs its mentioned - This method uses the given calendar to construct an appropriate millisecond value for the timestamp if the underlying database does not store timezone information.

Is that Calander time zone parameter only works if the database does not store timezone information?

I am trying to retrive data using Locale.

In database my date is 2005-05-15 15:00:00. I am running my Local web server in CST time zone.

When I retrive value from database using Pacific time zone, I am getting same date and time.
rs.getTimestamp(5, cal) --> 2005-05-15 15:00:00.0

Even without using timezone, I am getting same result
rs.getTimestamp(5) --> 2005-05-15 15:00:00.0
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

When I retrive value from database using Pacific time zone
And how exactly do you do that? And for that matter, how do you retrieve data using a Locale? I have always used SQL to retrieve data. Clarification would help.
Mukesh Mittal
Ranch Hand

Joined: Jan 13, 2006
Posts: 31
I am retriving data from sybase database using JDBC.

rs.getTimestamp(field index, Cal)

In Cal I setup pacific TimeZone. Without timezone and with timezone, system is giving me the same result.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

Then that suggests to me that the database already knows the timezone of the timestamp it's returning to you and doesn't require your assistance.

If you want to display a timestamp as if it were in some other timezone, then just get a SimpleDateFormat object and call its setTimeZone() method.

And there is no relationship between Locale and TimeZone.
Mukesh Mittal
Ranch Hand

Joined: Jan 13, 2006
Posts: 31
Thanks for the explaination.

I am trying to use time without using SimpleDateFormat. My impression is that, SimpleDateFormat is basically use for Display purpose.

I want to change time using PST or any other time zone for further processing. What's the purpose of setting timezone in calendar and then set date in that?

TimeZone t = TimeZone.getDefault();
t = TimeZone.getTimeZone("EST");

java.util.Calendar cal = java.util.Calendar.getInstance(t);

java.util.Date date = new java.util.Date();
cal.setTime(new java.sql.Timestamp(date.getTime()));


What's the purpose of setting timezone in java.util.Calendar?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql.ResultSet getTimestamp Locale issue
 
Similar Threads
date format conversion to MM/dd/yyyy hh:mm a
Util package date
Timezone getting Oracle date
Date printed in IST format when EDT format required
problem while inserting date field in oracle data base