Mysql 时间格式默认插入值为空时,会以'0000-00-00 00:00:00'填充,这时如果select时会抛出SQLExecption如下:
java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
解决方案:<property name="url"
value="jdbc:mysql://xxx.xxx.x.xxx:3306/库名?zeroDateTimeBehavior=convertToNull">
</property>
另还有一种解决方案:
方法二:select 语句中做如下处理:
SELECT ID, IF(createDate='0000-00-00 00:00:00','null',createDate)createDate FROM T_DateTest;
这里将createDate格式转换为”null“展示,不再抛出SQLException。