• 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

java.util.Date problem

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello frenz... I dont know if this question is to be asked in this group or not if not then plz forgive.. Actually i hv made and application in which I m supposed to start some device and then store the Start date and timein MySQL and then retrieve that date and time and show in GUI...
in java side I m using java.util.Date and in MYSQL table I m using simple Date(I guess that is java.sql.Date)

Now problem is I m getting the Date from GUI and converting it into java.sql.Date and then inserting. but it is storing only 0000-00-00. I dont know whats going wrong. i tried forums but none is clear enough. plz help me out

I want to show time also. I dont want to change either so plz give any round about.

code to enter java date in mysql is:


java.util.Date startTime = obj.getOperationTime();
java.sql.Date time=new java.sql.Date(startTime.getTime());

String updatdev = "update DeviceApplication set DeviceApplicationStatus ="
+ status + ", DeviceApplicationStartTime =" + new java.sql.Date(startTime.getTime())+ " where DeviceApplicationID =" + deviceID;
//Execute the Query
int i = stmt.executeUpdate(updatdev);



plz help
thanx
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the type of the field you are saving the data to. It is likely a date field (i.e. day-month-year) rather than a date and time field.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem is java.sql.Date, which designed to store Date info, but not Time. That also means it's .toString() method will return "yyyy-mm-dd".
Try to use Timestamp instead, or use PreparedStatement.setDate(1, yourJavaSqlDateVariable).
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic