Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC MS Access Date comparison

 
Simon Cockayne
Ranch Hand
Posts: 214
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am accessing an MS Access database via JDBC.

I can happily connect and retrieve a result set and even subset the results with string comparisons (wow!).

Now...each record contains a MS Access "Date/Time" field.

How can I specify in my SQL in my java method, that I only want to retrieve records that are newer than a given, date?

I am creating a string that stores my SQL query and passing this to the executeQuery() method.

I suppose I need to A) Define my comparisn date and then B) somehow pass that into my SQL query statement.

I am not sure how to do either...

All assistance is warmly welcomed.

Cheers,

Simon.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simon,
Since you are dealing with Dates, you will want to use a PreparedStatement. This lets the driver handle all the icky date details for you.

The query would go something like this:
"select columns from table where date_column > ?"

Then you can call:
preparedStatement.setDate(1, date);

For more details on the PreparedStatement, check the JDBC tutorial.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic