I am using primarily java.sql.date's in my project because it is so intimately driven by a database, and the values are hidden anyway. However, I've run across an initialization issue. I want to timestamp some database records that represent objects. When first stored, no prob- just use the SQL NOW() function. But when Java-timestamping, there's (appears to be) no constructor equivalent to the java.util.date(), which just puts the current millisecond into the new Date. It appears you have to do something like:
When I do a
I get "cannot find symbol; constructor Date()" error.
First, is this best way to do this (seems a little kludgy to me)? And, second, shouldn't java.sql.Date inherite java.util.Date's constructor?
Allen, Yes. You need to create the java.util.Date to get the milliseconds value. It is kludgy, but most people write a DateUtil library so the kludginess is only in one place.
As you've noticed a subclass doesn't have to define constructors with the same signatures as the superclass. And constructors aren't inherited like regular methods are so you don't get it automatically. This article explains why.