Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting From String to java.sql.Date

 
Gabriel Cane
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Swan
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic