• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Java Date andMS SQL sever datetime comparasion problem

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
I have date time problem in Hibernate , in hibernate mapping i have provided the type "timestamp" , In pesistent class I have a java.util.Date type varialbe in which i m saving current date time, in MS sql server table i have datetime type column to persist this variable.

following is the date time before storing and after loading from database :the problem is that
sometimes it returns true indicating that the date is same ,but someimes it gives false :
It should be always true while i compare both objects that is before persistence and after loading from the data base the persisted value for tha object:
i think this problem iss not bcoz of hibernae , it is MS sql server datetime and java Date calss type problem........plz eply me as soon as poosible , thanks in advance!

before storing Time obj1.getDate() = Wed Jun 23 10:21:56 GMT+05:00 2004
loading from database Time obj2.getDate()= 2004-06-23 10:21:56.093
Obj1.getDate().equals(obj2.getDate()) = true


before storing Time obj1.getDate()= Wed Jun 23 10:23:22 GMT+05:00 2004
loading from database Time obj2.getDate() = 2004-06-23 10:23:22.917
Obj1.getDate().equals(obj2.getDate()) time = false

before storing Time obj1.getDate() = Wed Jun 23 10:26:07 GMT+05:00 2004
loading from database Time obj2.getDate() = 2004-06-23 10:26:07.023
Obj1.getDate().equals(obj2.getDate()) Time = false

before storing Time obj1.getDate() = Wed Jun 23 10:27:18 GMT+05:00 2004
loading from database Time obj2.getDate() = 2004-06-23 10:27:18.497
Obj1.getDate().equals(obj2.getDate()) Time = true


before storing Time obj1.getDate() = Wed Jun 23 10:29:36 GMT+05:00 2004
loading from database Time obj2.getDate() = 2004-06-23 10:29:36.547
Obj1.getDate().equals(obj2.getDate()) Time = false
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like there is a mismatch in the java.util.Date and the database column type due to the millisecond field? If you are not interested in that kind of accuracy, try this

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've already constated the same bug in the jdbc driver provided by Microsoft. Sometimes, but not always, it loses 1 milisecond when storing to the database
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apparently, there are a number of problems with the MS SQL Server jdbc driver...general advice is to use the JTDS driver @ http://jtds.sourceforge.net
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic