程序使用select 语句查询数据时,出现以下异常:
java.sql.SQLException:Value ‘0000-00-00’ can not be represented as java.sql.Timestamp
网上查得的原因是:
‘0000-00-00 00:00:00’ 这个时间不能用 Java 来表示。
Java 中的时间都是从 1970 年开始的,这个 ‘0000-00-00 00:00:00’ 的时间,Java 表示不了,所以就抛出该异常。
解决:
在配置文件的 jdbcurl,添加参数 zeroDateTimeBehavior,如下:
url :jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=gbk&zeroDateTimeBehavior=convertToNull