wood burning stoves 2.0*
The moose likes JDBC and the fly likes searching a mysql database with a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "searching a mysql database with a string" Watch "searching a mysql database with a string" New topic
Author

searching a mysql database with a string

Adam Confino
Ranch Hand

Joined: Sep 03, 2009
Posts: 48
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.


Just Another Guy Hooked on Java
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Adam Confino
Ranch Hand

Joined: Sep 03, 2009
Posts: 48
Thanks. Knowing that a java.sql.date extends java.util.date helps a lot.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: searching a mysql database with a string
 
Similar Threads
Getting all the database names using java with MySql
Listing tables in mySQL
Store Java object in MySQL Database
avoid inserting empty string
how to define password column in hibernate