Mysql 报错java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timest
来源:互联网 发布:冈本淘宝旗舰店可靠吗 编辑:程序博客网 时间:2024/05/18 01:55
java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
问题描述,在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(默认值)的纪录,根据不同的配置,会返回不同的结果:
不配置:默认返回异常
zeroDateTimeBehavior=round 0001-01-01 00:00:00.0
zeroDateTimeBehavior=convertToNull null
但这样有可能会报新的Exception:
The reference to entity "characterEncoding" must end with the ';' delimiter
其原因可能是在Properties文件或者xml文件中忘记进行特殊符号的转译了,
jdbc:mysql://192.168.1.155:3306/diandi?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
需要改为:
jdbc:mysql://192.168.1.155:3306/diandi?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
有以下几类字符要进行转义替换:
<
<
小于号
>
>
大于号
&
&
和
'
'
单引号
"
"
双引号
- java.sql.SQLException: Value '0000-00-00 ' can not be represented as java.sql.Timest
- java.sql.SQLException: Value '0000-00-00 ' can not be represented as java.sql.Timest
- Mysql 报错java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timest
- ibatis java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timest
- Cause: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timest
- Cause: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timest
- 解决Value '0000-00-00 ' can not be represented as java.sql.Timest
- Err:java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Timestamp
- 问题解决:java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
- java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
- java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date 解决方法
- java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
- 问题解决:java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
- java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
- [DEBUG] “java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Timestamp”
- java.sql.SQLException:Value ‘0000-00-00′ can not be represented as java.sql.Date .
- java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.D
- 问题解决:java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
- ViewPager简单实现
- mui back 返回刷新页面方法
- hdoj 5256 序列变换 (LIS变形)
- google test 学习笔记1-google test primer.md
- C6678 单核烧写实验
- Mysql 报错java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timest
- 【win32】day08-位图的使用/坐标系和映射模式/文字和字体/对话框
- UVa 1585 Score(得分)
- 在Axis2中添加SOAP头
- Android 获取本地图片&图片上传至服务端
- css3 flex流动自适应响应式布局设计
- 1083 矩阵取数问题(动态规划)
- Android Studio中集成百度地图获取本地debug版本的签名证书SHA1值
- HTK学习笔记 (2)