File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes compare dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "compare dates" Watch "compare dates" New topic

compare dates

vivek, tiwari

Joined: Apr 13, 2001
Posts: 3
hi folks,
i was working to develop a scheduler....
i was able to upload a date into database (MS Access)
but i cannot retrieve this date back using a query
sample code
String query=new String();
query+="SELECT * FROM scheduler_master WHERE sdate=";
ResultSet rs = statement.executeQuery(query);
please help
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Two things:
1) In order to use the date as a String for matching it must be in an acceptable format for that database. If it is a date-time object then you must include the time also in order to get an equals match.
2) The date must be in quotes in order for it to be accepted as a String by the database:
should be
You may want to look into using the java.sql.Date class with a prepared statement to do the comparison for you.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
I agree. Here's the link:
subject: compare dates
jQuery in Action, 3rd edition