JDBC & Date/Time

I'm using PostGRESQLJDBC v. 8.2-505 ... a very recent JDBC driver, and the methods supplied in the ResultSet class include a getTime() method, which returns a 'Time' instance, and a getDate() method, which returns a 'Date' instance (assuming that I pass each method the name of a column within the result set corresponding to a date or time in the database).

Problem: Date and Time are both basically deprecated in favor of the 'Calendar' class. JDBC is fairly standarized, even between databases, yes? I'm a little new here to java... is there any kind of accepted practice here? There certainly isn't a getCalendar() method...

What is the standard way of wrapping time/date results from a database into a Java 'Calendar'? Please also note that the time and date values come from 2 different columns in the database in order to maintain SQL-cross compatibility... Please don't tell me I need to start parsing strings, here.

[957 byte] By [dcaudella] at [2007-11-27 10:11:43]
# 1

When using the getTime() and getDate() methods, you'll end up with a java.sql.Date and a java.sql.Time instances. Those two classes are subclasses of the java.util.Date class.

You should obtain full date/time information by adding time (milliseconds since epoch) values from those two instances.java.util.Date date = new java.util.Date(rs.getDate("TIME_COL").getTime() + rs.getTime("TIME_COL").getTime);

Note that the Date and Time classes are not deprectated, but thy shouldn't be no more built out of Year-Month-Day-etc.

TimTheEnchantora at 2007-7-28 15:15:25 > top of Java-index,Java Essentials,Java Programming...
# 2

Good call. Thanks!

dcaudella at 2007-7-28 15:15:25 > top of Java-index,Java Essentials,Java Programming...