Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.ResultSet getTimestamp Locale issue

 
Mukesh Mittal
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21583
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21583
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic