File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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());
 
Don't get me started about those stupid light bulbs.
 
subject: Converting From String to java.sql.Date
 
Similar Threads
Class java.sql.Date
java.sql.date to string
Database Abstract Factory
type casting issue
string convert in to Sql ate format