Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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.

 
Hold that thought. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic