• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Date comparison

 
Greenhorn
Posts: 27
Hibernate jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic