Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.util.Date problem  RSS feed

 
sandeep kumar jangra
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • 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
 
Joe Ess
Bartender
Posts: 9428
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Trish Dirac
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!