Hello,
I am working with JDBC and MySQL. I have a date column that I need included in my result set. Unfortunately, I cannot find a class in Java to retrieve the date. The SQL Date class is deprecated. How do you get Date objects from a result set?
Hello,
I am working with JDBC and MySQL. I have a date column that I need included in my result set. Unfortunately, I cannot find a class in Java to retrieve the date. The SQL Date class is deprecated. How do you get Date objects from a result set?
I don't think the java.sql.Date class itself it deprecated, only one of its constructors. You should be safe to continue using it.
You use java.sql.Date. A constructor and some methods are deprecated. The class isn't. Confused by this versus, say, java.util.Date or java.util.Calendar? Look at Making Sense of Java's Dates.
There are three JDBC date/time types:
The confusion probably arises from the fact that java.sql.Date extends java.util.Date and thus inherits its deprecated methods.
Just use the right type for the type of your column.
You can safely use the java.sql.Date class to map your MySQL DATE type. The java.sql.Date class extends the java.util.Date class, so you can use this object to do all types of date calculations.
Old post, but anyways:
I had problems with the granularity of java.util.Date and switched to java.util.Timestamp. I also experienced limited granularity with Timestamp type (up to seconds).
The columns in the database are declared as Date and to get the additional time part, I retrieved it as Timestamp. Problem is it truncates the value to seconds.
I investigated the Oracle default definition for timestamp which allows for 6 fractional digits.
I guess the Date part in the oracle definition limits the timestamp part in Java...
Cheers, Grazina