Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to generate sql date

 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String day = request.getParameter("day");
String month = request.getParameter("month");
String year = request.getParameter("xage");
how do I generate the sql date from these three integers
int d = Integer.parseInt(day);
int m = Integer.parseInt(month);
int y = Integer.parseInt(year);
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The deprecated Date(y, m, d) constructor sure was a lot easier to use if you don't need i18n (internationalisation).
- Peter
 
Dave Soto
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The deprecated Date(y, m, d) constructor sure was a lot easier to use if you don't need i18n (internationalisation).
- Peter

I know this post is OLD, but I just needed to say "YOU CAN SAY THAT AGAIN!"
I started my JDBC Date Fun trying to use DateFormat, but all of the methods return java.util.Date, not java.sql.Date. To the best of my knowledge (PLEASE correct me if anyone knows better) there is NO way (other than something similar to the above) to simply convert between java.util.Date and java.sql.Date. What a hassle.
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure if this is helpful to you, but one way to convert java.util.Date to java.sql.Date is :
new java.sql.Date(utilDate.getTime())
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also Ravindra, you can construct a sql Date by -
java.sql.Date.valueOf(s)
where s = a string in JDBC date escape format, "yyyy-mm-dd"
 
Dave Soto
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for the getTime() recommendation. That works wonderfully.
 
bhaskar nagaraja
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all,
Actually i am using calender class and Timestamp class adn storing the date with time in the sql database , but the thing is while retreiving the date , the second part of the time is not displaying , so can u suggest me how to get the date along wiht time along with seconds .
Thanks in advance,
bhaskar
[This message has been edited by bhaskar nagaraja (edited October 16, 2001).]
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use the resultset.getDate() method when retrieving value, use resultset.getTimestamp()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic