java.sql.SQLException: Value'0000-00-00'异常解决办法
2015-12-09 21:54
471 查看
在使用MySql 时, 数据库中的字段类型是timestamp的,默认为0000-00-00, 会发生异常:java.sql.SQLException: Value '0000-00-00 ' can not be represented as java.sql.Timestamp
解决办法:
给jdbc url加上 zeroDateTimeBehavior参数:
datasource.url=jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
zeroDateTimeBehavior=round是为了指定MySql中的DateTime字段默认值查询时的处理方式;默认是抛出异常,
对于值为0000-00-00 00:00:00(默认值)的纪录,如下两种配置,会返回不同的结果:
zeroDateTimeBehavior=round 0001-01-01 00:00:00.0
zeroDateTimeBehavior=convertToNull null
解决办法:
给jdbc url加上 zeroDateTimeBehavior参数:
datasource.url=jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
zeroDateTimeBehavior=round是为了指定MySql中的DateTime字段默认值查询时的处理方式;默认是抛出异常,
对于值为0000-00-00 00:00:00(默认值)的纪录,如下两种配置,会返回不同的结果:
zeroDateTimeBehavior=round 0001-01-01 00:00:00.0
zeroDateTimeBehavior=convertToNull null
相关文章推荐
- A Guide For Troubleshooting Workflow Notification Emails - Inbound and Outbound [ID 831982.1]
- mySQL中删除unique key的语法
- 让UIImageView适应图片的大小
- iOS 关于UIImage的压缩问题
- Android 笔记:AndroidTrain , Lint , build.gradle , 第三方库
- ubuntu12.04+ros fuerte 跑LsdSlam代码
- iOS开发UI篇—以微博界面为例使用纯代码自定义cell程序编码全过程(三·完结)
- abdroid hwui
- Putty和Xming创建远程GUI的SSH连接
- android120 zhihuibeijing 开机页面
- ERROR (DiscoveryFailure): Could not determine a suitable URL for the plugin
- nsq源码阅读笔记之nsqd(三)——diskQueue
- UIImageView的图片居中问题
- UITextView使用
- leetcode Longest Consecutive Sequence
- Error:ERROR ITMS-90474: "Invalid Bundle. iPad Multitasking support requires these orientations:
- Could not execute JDBC batch update : java.sql.BatchUpdateException: ORA-00926: 缺失 VALUES 关键字
- UE4连接Oculuse DK2设备
- UGUI之页面滑动(Grid Layout和Scorll Rect&&mask)
- [leetcode]Unique Paths II