springboot项目中的异常汇总

码农天地 -
springboot项目中的异常汇总

java.sql.SQLException: Zero date value prohibited
使用mybatis查询数据出现这个异常,解决方法是给jdbc加上一串参数:zeroDateTimeBehavior=convertToNull

官方手册给出的解释如下:http://dev.mysql.com/doc/connector-j/5.1/en/connector-j-installing-upgrading-3-0-to-3-1.html

Datetimes with all-zero components (0000-00-00 ...): These values cannot be represented reliably in Java. Connector/J 3.0.x always converted them to NULL when being read from a ResultSet.

Connector/J 3.1 throws an exception by default when these values are encountered, as this is the most correct behavior according to the JDBC and SQL standards. This behavior can be modified using the zeroDateTimeBehavior configuration property. The permissible values are:

exception (the default), which throws an SQLException with an SQLState of S1009.convertToNull, which returns NULL instead of the date.round, which rounds the date to the nearest closest value which is 0001-01-01.

大意是如果插入的记录的日期是0000-00-00 ...的情况,mysql无法解析这个日期,因此无法将这个记录返回到网页上。

特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。

Tags 标签

加个好友,技术交流

1628738909466805.jpg