Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date comparison

 
hemantha kumar k
Greenhorn
Posts: 27
Hibernate Java jQuery
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



here it the piece of code i'm using in my project vehicleDateOutReq.getText() from the vehicleDateOutReq field i'm taking the string and converting into date format into mysql comparable Date format to compare the date, but my ResultSet is not populating, but if use it in command prompt it is giving the output




it is returning the value

 
Paul Clapham
Sheriff
Pie
Posts: 20187
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally my advice would be to use a PreparedStatement when you want to deal with dates in the database. You did that, but you completely missed the point of PreparedStatement, which is that you can put "parameters" in the query and have the database driver deal with formatting them in the right way. So your query should look like this:

Notice that you don't have to worry about quoting or not quoting parameters, nor do you have to worry about formatting date parameters. Just call the appropriate setXXX methods of PreparedStatement.

The one thing you have to deal with is that JDBC wants a java.sql.Date but you have a java.util.Date. Or at least, you will have one after you convert your text string into one. Here's how to get a java.sql.Date from a java.util.Date:
 
hemantha kumar k
Greenhorn
Posts: 27
Hibernate Java jQuery
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Normally my advice would be to use a PreparedStatement when you want to deal with dates in the database. You did that, but you completely missed the point of PreparedStatement, which is that you can put "parameters" in the query and have the database driver deal with formatting them in the right way. So your query should look like this:

Notice that you don't have to worry about quoting or not quoting parameters, nor do you have to worry about formatting date parameters. Just call the appropriate setXXX methods of PreparedStatement.

The one thing you have to deal with is that JDBC wants a java.sql.Date but you have a java.util.Date. Or at least, you will have one after you convert your text string into one. Here's how to get a java.sql.Date from a java.util.Date:



thank you Paul Clapham it is working now
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic