码迷,mamicode.com
首页 > 数据库 > 详细

解决提示Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp;的方法

时间:2017-11-01 23:53:08      阅读:335      评论:0      收藏:0      [点我收藏+]

标签:插入   .sql   unicode   col   出错   utf8   时间段   log   coding   

Mysql在进行查询时报了一个

Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp;

这样的错误,这是因为在默认插入一个类型为timestamp的时间时它会将‘0000-00-00 00:00:00‘插入,但是在数据库定义时又因为设计是非空的timestamp类型的时间,所以查询时就会出错,并且mysql的时间范围是:‘1000-01-01 00:00:00‘ 到 ‘9999-12-31 23:59:59‘这个时间段,所以会报错,目前的解决办法是在jdbc连接文件中添加一句:

&zeroDateTimeBehavior=convertToNull

 

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

 

目前这个方法还是有用的,但是到了后边不知道会不会会有新的问题出现。

 

解决提示Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp;的方法

标签:插入   .sql   unicode   col   出错   utf8   时间段   log   coding   

原文地址:http://www.cnblogs.com/future-liu1121/p/7768926.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!