• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date comparison

 
hemantha kumar k
Greenhorn
Posts: 27
Hibernate Java jQuery
  • 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
Posts: 21973
36
Eclipse IDE Firefox Browser MySQL Database
  • 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
  • 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
 
Message for you sir! I think it is a tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!