• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

dates and JDBC

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Java Experts,

I am trying to take a date and put it into MySQL. I know there are a lot of ways to do this, but I am trying to use Simple Date Format "MM-DD-YYYY". I know how to parse a string and produce a date, but how would I take a date and parse it to a string in the MM-DD-YYYY format?

I've read about toPattern() and applyPattern() . Would either of these be helpful?

Thanks alot. I know your time is valuable.
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want the same pattern all the time, you can just add it to the construction of SimpleDateFormat

e.g. like this:

Otherwise you can do it like this sample:
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you want to convert a Date to a String? If you use a PreparedStatement then you can use the setDate method to work with the Date object directly. No need for any string operations - let JDBC do the work for you.
 
Adam Confino
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf,

Because I haven't gotten to "PreparedStatements" on the JavaTrail!

I'll be sure to read up on them!

Thanks,
Adam
 
reply
    Bookmark Topic Watch Topic
  • New Topic