解决提示Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp;的方法

Mysql在进行查询时报了一个java

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链接文件中添加一句:mysql

&zeroDateTimeBehavior=convertToNullsql

 

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

 

目前这个方法仍是有用的,可是到了后边不知道会不会会有新的问题出现。数据库

相关文章
相关标签/搜索