• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compare dates

 
vivek, tiwari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic