Subject | Re: How to retrieve a value from a Date field of a ResultSet |
---|---|
Author | dobedani |
Post date | 2006-05-24T08:31:36Z |
Dear Roman,
Yes, you are right. I used this:
out.println(d.getYear() + "-" + (d.getMonth() + 1) + "-" + d.getDay
());
instead of what I wrote earlier - sorry. And I should have used
getDate instead of getDay - thank you.
However, I hope you'll still look at my question again. You say I
should use Calendar. That's exactly what I want! But how do I do
this in this context? AFAIK, ResultSet hasn't got a method
getCalendar - only a method getDate. So, how do I obtain a Calendar
object with the date stored in a ResultSet's field? TIA
Kind regards,
Dobedani
--- In Firebird-Java@yahoogroups.com, "Roman Rokytskyy"
<rrokytskyy@...> wrote:
Yes, you are right. I used this:
out.println(d.getYear() + "-" + (d.getMonth() + 1) + "-" + d.getDay
());
instead of what I wrote earlier - sorry. And I should have used
getDate instead of getDay - thank you.
However, I hope you'll still look at my question again. You say I
should use Calendar. That's exactly what I want! But how do I do
this in this context? AFAIK, ResultSet hasn't got a method
getCalendar - only a method getDate. So, how do I obtain a Calendar
object with the date stored in a ResultSet's field? TIA
Kind regards,
Dobedani
--- In Firebird-Java@yahoogroups.com, "Roman Rokytskyy"
<rrokytskyy@...> wrote:
>works
>
> > I have a SQL query - stored in a variable sqlStr - as follows:
> > SELECT SUBSTR(FVALUE, 18, 100),
> > CAST(SUBSTR(FVALUE, 5, 14) AS DATE) AS FDate
> > FROM TSETTINGS
> > WHERE etc.
>
> > I tried this query in IBConsole - the underlying database is
> > Firebird ;-) Today's date was shown as: 23/05/2006, i.e. that
> > fine!the
>
> > Then I passed this query to method executeQuery of a Statement:
> > Statement stmt = fbconn.createStatement();
> > ResultSet rset = stmt.executeQuery(sqlStr
>
> > If any records are returned, I would of course like to retrieve
> > date and eventually to represent this date as a String - e.g.:d.getYear());
> > Date d = rset.getDate(2);
> > out.println(d.getDay() + "-" + (d.getMonth() + 1) + "-" +
>as
> > The result is not what one would expect. Today's date comes out
> > 0106-05-02! Yes, the methods getDay, getMonth and getYear areclass,
> > deprecated, I know! And I know how to work with the Calendar
> > but how to do so in this context? Any help would be appreciated.the day of
>
> Are you sure that was not 2-5-106? If you check the Javadocs of
> java.util.Date methods, you will learn that getDay() returns you
> week (0 - Sunday, 1 - Monday, 2 - Tuesday, and so on) and thegetYear()
> method returns you the year starting with 1900.
>
> So, you'd better use Calendar class to avoid further confusion :)
>
> Roman
>