解决提示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;

这样的错误,这是因为在默认插入一个类型为timestamp的时间时它会将'0000-00-00 00:00:00‘插入,但是在数据库定义时又因为设计是非空的timestamp类型的时间,所以查询时就会出错,并且mysql的时间范围是:'1000-01-01 00:00:00' 到 '9999-12-31 23:59:59'这个时间段,所以会报错,目前的解决办法是在jdbc连接文件中添加一句:

&zeroDateTimeBehavior=convertToNull

url=jdbc:mysql://localhost:3306/seckill?useUnicode=true&characterEncoding=utf8&&zeroDateTimeBehavior=convertToNull

目前这个方法还是有用的,但是到了后边不知道会不会会有新的问题出现。

原文地址:https://www.cnblogs.com/future-liu1121/p/7768926.html