java项目,使用MySQL,字段类型为timestamp,字段值默认为0000-00-00 00:00:00。
在解析数据时会抛出一个异常:
java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
我的解决方案是修改jdbc链接(新增参数:zeroDateTimeBehavior=convertToNull),如下所示:
修改前:
jdbc:mysql://localhost:3306/product?useUnicode=true&characterEncoding=utf8
修改后:
jdbc:mysql://localhost:3306/product?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull