Using MyBatis to query DATETIME type column data from MySQL table, if the column value is 0000-00-00 00:00:00, the program will throw exception Java.sql.SQLException. The following are the column properties.
pubtime DATETIME NULLDEFAULTNULL
Error Info
Error attempting to get column 'pubtime' from result set. Cause: java.sql.SQLException: Zero date value prohibited ; Zero date value prohibited; nested exception is java.sql.SQLException: Zero date value prohibited org.springframework.dao.TransientDataAccessResourceException: Error attempting to get column 'pubtime' from result set. Cause: java.sql.SQLException: Zero date value prohibited ; Zero date value prohibited; nested exception is java.sql.SQLException: Zero date value prohibited
Solutions
To set up zeroDateTimeBehavior=convertToNull in JdbcUrl. zeroDateTimeBehavior values can be EXCEPTION, ROUND, and CONVERT_TO_NULL. The default value of zeroDateTimeBehavior is EXCEPTION.