com.mysql.cj.exceptions.DataReadException: Zero date value prohibited

com.mysql.cj.exceptions.DataReadException: Zero date value prohibited
    at com.mysql.cj.result.SqlTimestampValueFactory.localCreateFromTimestamp(SqlTimestampValueFactory.java:99) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
    at com.mysql.cj.result.SqlTimestampValueFactory.localCreateFromTimestamp(SqlTimestampValueFactory.java:50) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
    at com.mysql.cj.result.AbstractDateTimeValueFactory.createFromTimestamp(AbstractDateTimeValueFactory.java:87) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
    at com.mysql.cj.protocol.a.MysqlTextValueDecoder.decodeTimestamp(MysqlTextValueDecoder.java:79) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
    at com.mysql.cj.protocol.result.AbstractResultsetRow.decodeAndCreateReturnValue(AbstractResultsetRow.java:87) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
    at com.mysql.cj.protocol.result.AbstractResultsetRow.getValueFromBytes(AbstractResultsetRow.java:241) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
    at com.mysql.cj.protocol.a.result.ByteArrayRow.getValue(ByteArrayRow.java:91) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
    at com.mysql.cj.jdbc.result.ResultSetImpl.getTimestamp(ResultSetImpl.java:923) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
    at com.mysql.cj.jdbc.result.ResultSetImpl.getTimestamp(ResultSetImpl.java:968) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
    at com.zaxxer.hikari.pool.HikariProxyResultSet.getTimestamp(HikariProxyResultSet.java) ~[HikariCP-3.2.0.jar!/:na]

原因:
数据库的日期时间字段的值为:0000-00-00 00:00:00

解决方法:
连接数据库的JDBC.URL增加参数 zeroDateTimeBehavior=convertToNull

完整示例:

jdbc:mysql://192.168.1.111:3306/shanhy_demo?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8

你可能感兴趣的:(com.mysql.cj.exceptions.DataReadException: Zero date value prohibited)