MYSQL:Cannot convert value ‘0000-00-00 00:00:00’ from column 10 to TIMESTAMP的解决办法

  • Post author:
  • Post category:mysql


今天从MYSQL数据库抓取时,发生了Cannot convert value ‘0000-00-00 00:00:00’ from column 10 to TIMESTAMP异常

baidu了一下,大概意思是MySQL中的Datetime值无法再JAVA中可靠的被表示,按照JDBC和SQL的标准默认情况下产生异常。


JDBC允许用下列的值对zeroDateTimeBehavior 属性来设置这些处理方式,


exception (the default), which throws an SQLException with an SQLState of S1009.

设置为exception 异常(缺省)用一个SQLState的s1009错误号来抛出一个异常

convertToNull, which returns NULL instead of the date.

设置为convertToNull,用NULL值来代替这个日期类型

round, which rounds the date to the nearest closest value which is 0001-01-01.

设置为round,则围绕这个日期最接近的值(0001-01-01)来代替


你可以修改你的jdbc连接

jdbc:mysql://localhost:3306/NovelSiteDB?user=root&password=123456&zeroDateTimeBehavior=round



版权声明:本文为kkgbn原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。