Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

java.util.date vs. java.sql.date  RSS feed

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

TIA
 
author & internet detective
Posts: 39283
727
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Allen Williams
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gotcha! Thanks, Jeanne.
 
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!