This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

searching a mysql database with a string  RSS feed

 
Adam Confino
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks. Knowing that a java.sql.date extends java.util.date helps a lot.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!