java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timest

在查询数据库时间类型时,如若出现时间格式错误如:0000-00-00 00:00:00  则会抛出

java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timest 错误


问题是时间类型存储错误,解决方案:

    jdbc.url=jdbc:mysql:ip地址:端口号数据库名称?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull

解决方案即是url后面添加加参数:zeroDateTimeBehavior=convertToNull


此参数是指定时间类型错误处理策略为:错误则指定为null

策略:

    1.exception(不指定,则默认)---->默认抛出异常,
    2.convertToNull------->转化为null
    3.round------->替换成最近的日期即XXXX-01-01



参考文章:

        https://blog.csdn.net/rendeyishi/article/details/25119029

        https://blog.csdn.net/sinat_30397435/article/details/72518215

url常用参数设置参考:

        https://www.cnblogs.com/yokoboy/archive/2013/03/01/2939315.html


猜你喜欢

转载自blog.csdn.net/qq_28325291/article/details/80769558