aspose file tools*
The moose likes JDBC and the fly likes how to generate sql date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to generate sql date" Watch "how to generate sql date" New topic
Author

how to generate sql date

ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
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);


SCJP, SCJD, SCWCD, SCBCD, SCEA
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252

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

Joined: Sep 15, 2001
Posts: 55
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

Joined: Jun 07, 2000
Posts: 87
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

Joined: Jun 07, 2000
Posts: 87
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

Joined: Sep 15, 2001
Posts: 55
Thanks very much for the getTime() recommendation. That works wonderfully.
bhaskar nagaraja
Greenhorn

Joined: Aug 10, 2001
Posts: 9
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

Joined: Jun 07, 2000
Posts: 87
Don't use the resultset.getDate() method when retrieving value, use resultset.getTimestamp()
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to generate sql date