wood burning stoves*
The moose likes JDBC 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "compare dates" Watch "compare dates" New topic
Author

compare dates

vivek, tiwari
Greenhorn

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=";
query+="10/10/2001";
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:
query+="10/10/2001";
should be
query+="'10/10/2001'";
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: http://aspose.com/file-tools
 
subject: compare dates
 
Similar Threads
Syntax error in SQL
date and query
Date conversion
sql query involving dynamic date
Could u help me to improve???