File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Date comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
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
Bartender

Joined: Oct 14, 2005
Posts: 18141
    
    8

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Date comparison
 
Similar Threads
how to get dynamic data from the oracle back end
ClassNotFoundException with ResourceBundle
java.text.ParseException
Are there any problems using the same statement for multiple queries?
Oracle Timestamps and java.