• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing java.sql.date to constructors

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm writing a program where I need to pass the java.sql.date in the constructor. When I started to test this code, it would not compile because of the format of the date. This is the format that I used:

January 1, 2000 01:01:01.001

The compiler does not like this format. I tried taking out spaces and that didn't work. I shouldn't take out the other symbols, should I? What format should the java.sql.date be in when passed to a constructor.

Thanks!
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the API docs for 1.5, there is only one constructor of java.sql.Data (that is recommended. There is one that is deprecated). It accepts a long.
 
Adrienne Peck
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to put that date in as a long. However, eclispe states that the number should be an integer. So, I can put in the CCYYMMDDHH just fine. Not able to put in minutes and seconds.

How can the java.sql.Date object be an integer? Does this mean that something else needs to happen once that value is passed in?

I was thinking of doing the following with the date that is passed in:

new java.sql.Date(new GregorianCalendar().getTimeInMillis());

Would this get the MMDDSS time that we need from java.sql.Date object?
 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
got hru this link http://www.javaworld.com/jw-12-2000/jw-1229-dates.html
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This works for me:



I hope it helps!
 
Adrienne Peck
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be even simpler to omit the "01:01:01.001" part, since java.sql.Date models only a date with no time component.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic