File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes JDBC MS Access Date comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "JDBC MS Access Date comparison" Watch "JDBC MS Access Date comparison" New topic

JDBC MS Access Date comparison

Simon Cockayne
Ranch Hand

Joined: Dec 09, 2000
Posts: 214

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.



SCJP 1.4 (93%)<br />SCJD (In progress. It can run, but it can't hide...)
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: JDBC MS Access Date comparison
It's not a secret anymore!