compering 2 dates and get the resultset in sql

the following code does not work to compare two days in access database and the date instantiated from date class please help me to solve this problem with this code or your own simple code. thanks.
 
import java.text.*;
import java.sql.*;
import java.sql.SQLException.*;

public class DatabaseCmd
{
     Connection con;
     Statement stmt;
     ResultSet rs;
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", java.util.Locale.US);
     
     public DatabaseCmd(String name)
     {
          java.util.Date date = dateFormat.parse(name, new ParsePosition(0));
          try
          {
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               con =DriverManager.getConnection("jdbc:odbc:idm");               stmt=con.createStatement();
               
               rs=stmt.executeQuery("SELECT * FROM student WHERE Date='"+date+"'");
               while(rs.next())
               {
                    System.out.print(rs.getString(1)+"  ");
                    System.out.print(rs.getString(2)+"  ");
                    System.out.println(rs.getDate(3));
               }
          }
          catch(Exception eee){System.out.println(eee);}
     }

     public static void main(String args[])
     {
          DatabaseCmd a=new DatabaseCmd(args[0]);
     }    
}
KMAWijayasinhaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
Use a prepared statement.
something like:

public class DatabaseCmd
{
    Connection con;
    PreparedStatement stmt;
    ResultSet rs;
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", java.util.Locale.US);
   
    public DatabaseCmd(String name)
    {
         java.util.Date date = dateFormat.parse(name, new ParsePosition(0));
         try
         {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              con =DriverManager.getConnection("jdbc:odbc:idm");               stmt=con.prepareStatement("SELECT * FROM student WHERE Date=?");
              stmt.setDate(new java.sql.Date(date.getTime());
              rs=stmt.executeQuery();
              while(rs.next())
              {
                   System.out.print(rs.getString(1)+"  ");
                   System.out.print(rs.getString(2)+"  ");
                   System.out.println(rs.getDate(3));
              }
         }
         catch(Exception eee){System.out.println(eee);}
    }

    public static void main(String args[])
    {
         DatabaseCmd a=new DatabaseCmd(args[0]);
    }    
}

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CleanupPingCommented:
KMAWijayasinha:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.