Java:出现错误提示(java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date)

Java:出现错误提示(java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date)

原因分析:

 “0000-00-00 00:00:00”在mysql中是作为一个特殊值存在的,但 java.sql.Date 将其视为 不合法的值 格式不正确;

解决方案:

 url加上zeroDateTimeBehavior参数(其中&是&的转义);

 datasource.url=jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull

 注意:如果数据库连接是在xml中配置,需要进行特殊字符转义;

   

原文地址:https://www.cnblogs.com/lizm166/p/8268399.html