首页 > 代码库 > mysql解决Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp

mysql解决Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp

 

  同步发布:http://www.yuanrengu.com/index.php/mysqlsolvetimestamp.html

  在使用mysql时,如果数据库中的字段类型是timestamp,默认为0000-00-00,会发生异常:Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp.

    解决办法如下:

    给数据库的jdbc.url加上zeroDateTimeBehavior参数,如下:

jdbc.url=jdbc:mysql://localhost:3306/table?characterEncoding=UTF-8&zeroDateTimeBehavior=round

  zeroDateTimeBehavior参数有两种配置:

  • zeroDateTimeBehavior=round ,”0000-00-00“会默认转换为”0001-01-01 00:00:00”
  • zeroDateTimeBehavior=convertToNull,“0000-00-00“会转换为null

mysql解决Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp