jdbc:mysql://localhost:3306/mydbname?zeroDateTimeBehavior=convertToNull
当java通过jdbc 操作mysql数据库,其中有timestamp字段时,如果其值为‘0000-00-00 00:00:00’时,读取的时候会报错
Cannot convert value '0000-00-00 00:00:00' from column 5 to TIMESTAMP.
原因是其中有‘0000-00-00 00:00:00’这个值。两种解决方法:
1.在连接字符串中加入zeroDataTimeBehavior=converToNull;jdbc:mysql://localhost:3306/mydbname?zeroDateTimeBehavior=convertToNull
2.避免在数据库中timestamp字段插入‘0000-00-00 00:00:00‘值。当涉及到timestamp字段的时候,可以用用now()函数来代替!