• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MS Access date search missing record

 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Noticed an oddity in MS Access using JDBC (sun.jdbc.odbc.JdbcOdbcDriver). I was performing a range query on a date value, aka "SELECT * FROM ... WHERE myDateColumn <= someValue". When myDateColumn and someValue where the same for a particular row, the query failed to return the row. If I add 999 milliseconds to someValue in Java before running the query, the record is returned. If I add 998 milliseconds to someValue in Java before running the query, the record is not returned. This is a PreparedStatement so I'm not converting the date/time directly.

To verify the data in the column, I retrieved all rows in Java and ran getTime() on the myDateColumn values. According to the results, myDateColumn and someValue (without modification) have the exact same epoch value in Java.

Any ideas? I suspect this might be a data error or round off error, but I really hope its not a driver or Access error.
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When working with days in any Microsoft database product, I prefer to use DATEDIFF.
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob, I'll try it out. I do prefer to avoid database functions when possible but pure SQL software systems are hard to construct in the real world.
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It worked with DATEDIFF, but I'm left to wonder why the following aren't exactly equivalent, when using PreparedStatements for handling date/time conversions considering Access does not support milliseconds.

 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the actual value of someValue? Perhaps it's being converted incorrectly when used with <=.
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java date with time rounded to nearest second. When I pull the epoch times of both values they are the same.
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But in what format is the date? I always prefer to send date literals in "yyyy-MM-dd HH:mm:ss" or "yyyy-MM-dd HH:mm:ss.SSS" format to make sure there's no odd date conversion. Especially dates like 01-06-2012 can cause troubles. On one system it's January 6th, on others it's June 1st.
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The value is only off by 1 second not 5 months. The values are entered correctly.
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's then just agree that Access is a horrible product I still use it as well for non-production purposes sometimes. In production environment it should be avoided.
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or the driver is. I can't help but thinking this is a bug in the driver, but debugging faulty JDBC drivers is unfun.
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic