how to save a Date instance into MS Access?

ok, i have this:
Date d = new Date();

and now i wanted to save it to my db:
      try{
            String query = "INSERT INTO MyTable(Date) VALUES(" +d + ")";
           
            PreparedStatement stmt = dbConn.prepareStatement(query);
            stmt.executeUpdate();
      }catch(SQLException sqlex){
           sqlex.printStackTrace();
      }

but it throws this:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Tue Jul 05 22:11:59 PDT 2005'.

i inserted int, String into different fields and they work ok, but not the date..
can anyone help?
JAVAnewbieAsked:
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.

JAVAnewbieAuthor Commented:
or at least put me to the right way to save and date.

i was thinking to save the date as a String - d.toString() and change the date field to be text.
but when i wanted to retrieve the date, how can i change it back to Date instance?
InNoCenT_Ch1ldCommented:
http://www.javaalmanac.com/egs/java.sql/InsertPs.html?l=find

      Date d = new Date();
      java.sql.Date d2 = (java.sql.Date)d;
      try{
            String query = "INSERT INTO MyTable(Date) VALUES(?);
           
            PreparedStatement stmt = dbConn.prepareStatement(query);
            stmt.setDate(1, d2);

            stmt.executeUpdate();
      }catch(SQLException sqlex){
           sqlex.printStackTrace();
      }
InNoCenT_Ch1ldCommented:
sorry, it's
java.sql.Date d2 = new java.sql.Date(d.getTime());
InNoCenT_Ch1ldCommented:
to retrieve

        String query = "SELECT * FROM Table";
       
        PreparedStatement stmt = dbConn.prepareStatement(query);
        ResultSet rs = stmt.executeQuery();
       
        if(rs.next()){
            Date d = rs.getDate("Date");
            System.out.println("Date: " + d.toString());
            System.out.println("Time: " + new Date(d.getTime()));
        }
        stmt.close();

  output:
      Date: 2005-07-05
      Time: Tue Jul 05 00:00:00 PDT 2005

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
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.