Subject Re: How to retrieve a value from a Date field of a ResultSet
Author dobedani
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:
>
>
> > 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
works
> > fine!
>
> > 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
the
> > date and eventually to represent this date as a String - e.g.:
> > Date d = rset.getDate(2);
> > out.println(d.getDay() + "-" + (d.getMonth() + 1) + "-" +
d.getYear());
>
> > The result is not what one would expect. Today's date comes out
as
> > 0106-05-02! Yes, the methods getDay, getMonth and getYear are
> > deprecated, I know! And I know how to work with the Calendar
class,
> > but how to do so in this context? Any help would be appreciated.
>
> 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
the day of
> week (0 - Sunday, 1 - Monday, 2 - Tuesday, and so on) and the
getYear()
> method returns you the year starting with 1900.
>
> So, you'd better use Calendar class to avoid further confusion :)
>
> Roman
>