• 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

searching a mysql database with a string

 
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 Greats,

I would like to create a feature where a user can input a string (MM-dd-yyyy) and it returns all matches from the mysql database. I know JDBC does a lot under the covers, but wouldn't I need to do some manual coding because it is a search method? If the answer is yes, how do I take a string and convert it to a java.sql.date object and then to a java.util.date object.

Thanks for your help. It is appreciated very much.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


but wouldn't I need to do some manual coding because it is a search method?


Yes. You'll need to parse the date, build some SQL, create a PreparedStatement, run this then interpret the results.

The java.util.SimpleDateFormat and java.util.DateFormat class are the ones to look at to get the string parsing date format stuff. I'd recommend providing some control that doesn't allow free text input for dates though; there are 1001 different possible formats to describe the same thing.

By the way java.sql.Date is a java.util.Date.
 
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
Thanks. Knowing that a java.sql.date extends java.util.date helps a lot.

 
reply
    Bookmark Topic Watch Topic
  • New Topic