java.sql.SQLException: Zero date value prohibited 异常处理

Recently, when using MyBatis, I found the exception of java.sql.SQLException: Zero date value prohibited. I checked the reason online. In fact, when the Mysql database is faced with the processing of the 0000-00-00 00:00:00 date, if no corresponding countermeasures are set, an exception will occur.

So the solution is to set the processing zeroDateTimeBehavior in jdbcUrl to deal with , generally there are the following:

1.driver-url=jdbc:mysql://127.0.0.1/test?zeroDateTimeBehavior=convertToNull

ZERO date will be converted to null

2.driver-url=jdbc:mysql://127.0.0.1/test?zeroDateTimeBehavior=round

The ZERO date will be converted to 0001-01-0100:00:00.0, which is equivalent to adding a year

In general, it is better to use convertToNull , converting the date to null is more in line with the meaning of the ZERO date

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325321695&siteId=291194637