Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

时间:2024-05-27 20:03:20

1、问题场景描述:后台方法中执行查询返回list列表中,执行后台产生运行时异常 java.sql.SQLException:Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

2、问题排查和解决:排查代码,无编译时错误,断点调试,更具控制台找到对应的报错地方:

Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

断点调试发现,就是数据库交互时返回值接收时候发生异常:

Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

代码没有问题,排查数据库,因为是时间戳的错误:

Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

找相关时间的字段,发现存在单个对象的属性值其对应的数据库字段类型为date或者datetime类型但是值为0的情况,如0000-00-00:

Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

将相关字段改为正常的时间点值,再次执行,问题解决。