aspose file tools*
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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC MS Access Date comparison" Watch "JDBC MS Access Date comparison" New topic
Author

JDBC MS Access Date comparison

Simon Cockayne
Ranch Hand

Joined: Dec 09, 2000
Posts: 214
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.


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

Joined: May 26, 2003
Posts: 31073
    
232

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.


[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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC MS Access Date comparison