from http://ondra.zizka.cz/stranky/programovani/java/index.texy
When working with MySQL over JDBC and the driver encounters a zero DATE, TIME, or DATETIME value (that is, e.g, ‚0000–00–00‘ for DATE), an exception is thrown:
java.sql.SQLException: Cannot convert value '0000-00-00 00:00:00' from column 4 to TIMESTAMP.
In this case, using SQL commands like
SET GLOBAL sql_mode = 'NO_ZERO_DATE';
does not help much, because that works only in „strict SQL mode“, and needs to be set for every connection, or globally for the whole server.
What helps is setting JDBC driver’s zeroDateTimeBehavior property to convertToNull:
What should happen when the driver encounters DATETIME values that are composed entirely of zeroes (used by MySQL to represent invalid dates)? Valid values are “exception”, “round” and “convertToNull”.
The way to set it depends on the way you configure JDBC driver. The most common case is to use connection URL parameters. In my case it reads:
jdbc:mysql://localhost/test?zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=UTF-8&characterSetResults=UTF-8
