This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sql.Date problem

padma patil
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Folowing is my senario,
1) I am reading Form input text field 'Date' as
String str1=request.getParameter("Date");
which accepts input in yyyymmdd format.
eg: str1="20020422"
2) I want to store this Date into table with column type Date
AssignedOn Date
3)I am using PrepareStatement to insert values into table.
problem here is Datevar must be sql.Date type
4)I am converting String to sql Date as
Long l1=new Long(str1);
long l2=l1.longValue();
Date d1= new Date(l2);
System.out.println("long value:"+ l2);
System.out.println("Date:"+ d1.toString());
First print prints:long value:4122002
Second prints : Date:1969-12-31
Why it is taking wired value?
I even try by giving String in 'mmddyyyy' format
it prints 1969-12-31.
what's happening here?
Please let me any one knows any other way to store Date value(which is from htnl form) in table.
[ April 22, 2002: Message edited by: padma patil ]
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The constructor for Date that takes a long as an argument creates a date based on the number of milliseconds since January 1 1970 at 00:00:00 not the date itself.
To do what you are trying to do why ot just take the date you get and add the dashes (-) into it separate the yyyy-mm-dd and then just store it that way?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic