java.sql.SQLException: Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp
今天在项目中涉及到需要查询表中数据的时候,因为表中含有"CREATE_TIME字段",导致在select语句查询时报错。
Timestamp t = new Timestamp(System.currentTimeMillis())
System.out.println(t);
2020-06-29 16:57:43.663
可以明显的看出,java中的时间是从格林威治时间 1970年01月01日00时00分00秒开始的,这就导致"0000-00-00 00:00:00"Java根本无法表示此时间
解决
<jdbcConnection userId="root" password="xxx" driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.145.130:3306/test?zeroDateTimeBehavior=convertToNull"/>
或者
?zeroDateTimeBehavior=round
- 2.第一种方式试了,没用。然后,将数据库表字段"CREATE_TIME"改成
alter table 表名 modify CREATE_TIME timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间';