This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
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
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: compare dates
jQuery in Action, 3rd edition