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

Problem Reading/Writing Date

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I'm having a few major issues with Date over jdbc.

i) when i read a date out from my mysql database it cast it into java.util.Date to store in an object(errors if i try to store as java.sql.Date). Later on i have major problems trying to compar this date object...



ii) the second probelm is writing date to the db through jdbc. I set the date from todays date, cast it to java.sql.Date but when i write it to the db. i get 00-00-0000 in the db

Obviosly there is somethign strange going on between java.util.Date and java.sql.Date. Any help would be appreciated.

Cheers
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You better use Timestamp instead of Date.
Yongping
 
author & internet detective
Posts: 42135
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To expand on Yongping's comment:

- java.sql.Date is the date without any time value
- java.sql.Time is the time without any date value
- java.sql.Timestamp is both the date and time
 
Jamie Wool
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does that mean you can't compare java.sql.Date fields properly? I need the application to work out whether an item is out of date, so the precision is in terms days.

Also how do you write dates or timestamps through jbbc, as at the moment I have to use a sql based function like now(), because i simply get nulls if i attempt to pass a date. What i've been doing converting a java.util.Date to java.sql.Date, and passing that date across in the jdbc code? Is this not correct.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic