This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Date comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Date comparison" Watch "Date comparison" New topic
Author

Date comparison

hemantha kumar k
Greenhorn

Joined: Apr 20, 2010
Posts: 27




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

Joined: Oct 14, 2005
Posts: 19757
    
  10

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

Joined: Apr 20, 2010
Posts: 27

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
 
subject: Date comparison
 
It's not a secret anymore!