插入Mysql异常之Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
2016-03-29 18:44
1201 查看
问题描述, 在java应用程序中,数据表中有记录的time字段(属性为timestamp)其值为:“0000-00-00 00:00:00”
程序使用select 语句从中取数据时出现以下异常:
java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
这是因为 “0000-00-00 00:00:00”在mysql中是作为一个特殊值存在的,但是在Java中, java.sql.Date 会被视为 不合法的值,被JVM认为格式不正确。
解决办法:
在jdbc的url加上 zeroDateTimeBehavior参数:
datasource.url=jdbc:mysql://localhost:3306/pe?useUnicode=true&characterEncoding=gbk &zeroDateTimeBehavior=convertToNull
对于值为0000-00-00 00:00:00(默认值)的纪录,根据不同的配置,会返回不同的结果:
不配置:默认返回异常
程序使用select 语句从中取数据时出现以下异常:
java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
这是因为 “0000-00-00 00:00:00”在mysql中是作为一个特殊值存在的,但是在Java中, java.sql.Date 会被视为 不合法的值,被JVM认为格式不正确。
解决办法:
在jdbc的url加上 zeroDateTimeBehavior参数:
datasource.url=jdbc:mysql://localhost:3306/pe?useUnicode=true&characterEncoding=gbk &zeroDateTimeBehavior=convertToNull
对于值为0000-00-00 00:00:00(默认值)的纪录,根据不同的配置,会返回不同的结果:
不配置:默认返回异常
相关文章推荐
- Cursor query详解
- IOS开发-UI学习-delegate(代理)的使用,键盘消失
- UIView背景图片设置一些技巧
- iOS Build Question
- build/envsetup.sh
- 【iOS】UITextView 自动跳动的问题
- 【杭电】[1242]Rescue
- 51Nod 算法马拉松12 Rikka with sequences
- hdu 2062 Subset sequence
- 关于xmlhttprequest的readystate属性的五个状态
- 在T-SQL语句中访问远程数据库(openrowset/opendatasource/openquery)
- XMLHTTPRequest状态status详解
- Range Sum Query - Mutable
- UISearchBar改变输入框的背景色
- IOS学习之——UINevigationController 导航控制器
- ios生成guid代码
- IOS学习之——UIPickerView 点菜系统
- This certificate has an invalid issuer
- Java 1.8 ASM ClassReader failed to parse class file - probably due to a new Java class file version
- iOS could not build module