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

时间:2023-03-09 05:55:02
java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

下面是我查询数据库时打印出来的异常信息:

### Error querying database.  Cause: java.sql.SQLException:

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

异常分析:

  在使用MySql时,如果数据库中有字段类型是timestamp的,且如果我们不为它赋值的话,默认为‘0000-00-00’。

  但在这种状况下查询数据库是会发生异常的:java.sql.SQLException: Value '0000-00-00 ' can not be represented as java.sql.Timestamp

解决办法:

  给类型为timestamp的字段赋值即可。