wood burning stoves 2.0*
The moose likes JDBC 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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
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
internet detective

Joined: May 26, 2003
Posts: 30136

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.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
subject: JDBC MS Access Date comparison
Similar Threads
parsing in servlet
JDBC connection to MS SQL Server .. HELP
Access Data source using program
time for database access
how to update multiple table in frame