当前位置:Gxlcms > 数据库问题 > Mysql 时间格式默认空串 '0000-00-00 00:00:00' select抛出异常的解决方法

Mysql 时间格式默认空串 '0000-00-00 00:00:00' select抛出异常的解决方法

时间:2021-07-01 10:21:17 帮助过:5人阅读

 

解决方法如下:

方法一:jdbc的url加zeroDateTimeBehavior参数: 

datasource.url=jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true 

zeroDateTimeBehavior=round是为了指定MySql中的DateTime字段默认值查询时的处理方式;默认是抛出异常,

(摘自:http://www.blogjava.net/hilor/articles/164814.html)

 

方法二:select 语句中做如下处理:

SELECT ID, IF(createDate=‘0000-00-00 00:00:00‘,‘null‘,createDate)createDate FROM T_DateTest;

这里将createDate格式转换为”null“展示,不再抛出SQLException。

 

Mysql 时间格式默认空串 '0000-00-00 00:00:00' select抛出异常的解决方法

标签:

人气教程排行