无法将“0000-00-00 00:00:00”转换为TIMESTAMP [英] Cannot convert '0000-00-00 00:00:00' to TIMESTAMP

查看:153
本文介绍了无法将“0000-00-00 00:00:00”转换为TIMESTAMP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

字段定义

 /** 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....

推荐答案

我将在这里猜测你正在使用MySQL :-)它将零日期用作特殊占位符 - 不幸的是,JDBC无法处理它们默认情况下

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.

解决方案是将zeroDateTimeBehavior = convertToNull指定为MySQL连接的参数(在数据源URL或附加属性中),例如: p>

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

这将导致所有这些值被检索为NULL。

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

这篇关于无法将“0000-00-00 00:00:00”转换为TIMESTAMP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆