An exception is thrown when MySQL queries the default time.
The problem occurs when a mysql table is created, with a field of the Date type in the table. The default value is 0000-00-00 00:00:00. PrepareStatement is used for query, and the query result is ResultSet, the Date Field Retrieved From the result uses ResultSet. getDate ("XXXX"), the result throws an exception: java. SQL. SQLException: Value '2017-00-00 'can not be represented as java. SQL. date.
The cause of the problem is that the default value of Date in Mysql is "0000-00-00 00:00:00", but java. SQL. Date considers this as an invalid value, so the above exception is thrown.
Solution: add the zeroDateTimeBehavior parameter to the connection URL of mysql. This parameter can be used to specify the reason for converting this value when such a default value is encountered. There are two solutions, one is to convert to "0001-01-01 00:00:00", the other is to convert directly to Null. The corresponding configuration in sequence is as follows:
String url = "jdbc: mysql: // localhost: 3306/test? ZeroDateTimeBehavior = round "; // convert to" 0001-01-01 00:00:00"
String url = "jdbc: mysql: // localhost: 3306/test? ZeroDateTimeBehavior = convertToNull "; // convert to Null