Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot convert '0000-00-00 00:00:00' to TIMESTAMP

the field definition

 /** Date. */   @Column(columnDefinition = "datetime")   private Date date; 

setter

public void setDate(final Date date) {     DateFormat dfmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");     try {       this.date = dfmt.parse(dfmt.format(date));     } catch (ParseException e) {       // TODO Auto-generated catch block       e.printStackTrace();     }    } 

Does anyone have idea how to convert "zero date" into proper value ? Because i have error:

Cannot convert value '0000-00-00 00:00:00' from column 13 to TIMESTAMP 

And even if i set "default" field and setter like this:

/** Date. */       @Column       private Date date;   public void setDate(final Date date) {       this.date = date;      } 

I'll still have the same problem....

like image 702
Oleksandr Avatar asked Sep 01 '09 16:09

Oleksandr


1 Answers

I'm going to take a wild guess here that you're using MySQL :-) It uses "zero dates" as special placeholder - unfortunatelly, JDBC can not handle them by default.

The solution is to specify "zeroDateTimeBehavior=convertToNull" as parameter to your MySQL connection (either in datasource URL or as an additional property), e.g.:

jdbc:mysql://localhost/myDatabase?zeroDateTimeBehavior=convertToNull 

This will cause all such values to be retrieved as NULLs.

like image 189
ChssPly76 Avatar answered Oct 04 '22 01:10

ChssPly76