Subject Re: [Firebird-Java] How to retrieve a value from a Date field of a ResultSet
Author Roman Rokytskyy
> 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