This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Passing to constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Passing to constructors" Watch "Passing to constructors" New topic

Passing to constructors

Adrienne Peck

Joined: Jul 10, 2006
Posts: 29

I'm writing a program where I need to pass the 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 be in when passed to a constructor.

Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
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

Joined: Jul 10, 2006
Posts: 29
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?
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1372
got hru this link
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
This works for me:

I hope it helps!
Adrienne Peck

Joined: Jul 10, 2006
Posts: 29
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

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.
jQuery in Action, 2nd edition
subject: Passing to constructors
Similar Threads
Passing specific format date to callable statement
sql date convert
Date differences in months...
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Opti onal fature not implem