aspose file tools*
The moose likes Java in General and the fly likes Converting From String to java.sql.Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Converting From String to java.sql.Date" Watch "Converting From String to java.sql.Date" New topic
Author

Converting From String to java.sql.Date

Gabriel Cane
Ranch Hand

Joined: Mar 27, 2001
Posts: 39
I'd like to know, using non-deprecated methods, how I could take a String and convert it to a java.sql.Date object.
For example, my web application will be receiving three pieces of information:
month, day, year.
I've been fooling around with the Calendar object and I can't quite figure it out.
Thanks.


Sun Certified Programmer for the Java 2 Platform
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Here is some code to get you started, does very basic date validation:

Also have a look at java.text.SimpleDateFormat for further info.
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
I forgot to mention, to go from a java.util.Date to java.sql.Date, use something like:
java.util.Date date = (see above);
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting From String to java.sql.Date