Value '0000-00-00' can not be represented as java.sql.Date
Value '0000-00-00' can not be represented as java.sql.Date
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
有以下几类字符要进行转义替换:
< |
< |
小于号 |
> |
> |
大于号 |
& |
& |
和 |
' |
' |
单引号 |
" |
" |
双引号 |
Value '0000-00-00' can not be represented as java.sql.Date的更多相关文章
- java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Date
架构使用jsp+servlet+java+mysql mysql里time字段类型为datetime java实体类中该字段类型为Date 页面中,时间字段类型为空的信息显示不出来,且报错信息如下: ...
- Java:出现错误提示(java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date)
Java:出现错误提示(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
问题描述: 数据表中有记录的time字段(属性为timestamp)其值为:“0000-00-00 00:00:00” 程序使用select 语句从中取数据时出现以下异常: Java.sql.SQLE ...
- Value '0000-00-00' can not be represented as java.sql.Date解决办法
java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp 问题描述 ...
- mssql-异常value '0000-00-00' can not be represented as java.sql.Date
Mysql开发中采用ResultSet取值時,不管是才用getString()还是用getDate(),或者getObject,均会拋出如题所述异常.查阅Mysql官方Bug咨询: 是因为日期型(Da ...
- '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp error
'0000-00-00 00:00:00' can not be represented as java.sql.Timestamp error 异常现象 ### Cause: java.sql.SQ ...
- mysql解决Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp
同步发布:http://www.yuanrengu.com/index.php/mysqlsolvetimestamp.html 在使用mysql时,如果数据库中的字段类型是timestamp,默认为 ...
- 错误:Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp;的解决
问题: 代码中查询MySQL的结果集时报错,提示Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp;刚开始 ...
- java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
下面是我查询数据库时打印出来的异常信息: ### Error querying database. Cause: java.sql.SQLException: Value '0000-00-00 0 ...
随机推荐
- myeclipse连接数据库oracle(添加jdbc.properties)
第一步:在src下面建一个包com.xsl.conf 第二步:在建好的包下面新建一个jdbc.properties 第三步:在jdbc.properties里写入内容如下: driver = orac ...
- 定时发布任务,在global.asax中获取文件的物理路径的方法
如果要把一个相对路径或者虚拟路径映射道服务器的物理路径,通常会使用Server.MapPath()函数,比如将根目录下的html目录映射为物理路径:Server.MapPath("html& ...
- namenode无法启动
查看日志错误信息关键语句: There appears to be a gap in the edit log. We expected txid 44353, but got txid 原因: n ...
- js一些小知识点
1.isNaN(),里面传一个参数,用来判断传入的值是否是数字.可以用来做一些简单的表单判断. 2.用innerHTML属性可以操作(包括获取和设置)span的内容,实际上对所有非表单元素都可以用in ...
- JqGrid相关操作
JqGrid相关操作 根据jqGrid的文档,要想生成一个jqGrid,最直接的方法就是:$("#grid_id").jqGrid(options);也就是通过选择符得到一个tab ...
- ZZNU 1163: 在线判题(指针专题)
题目描述 Ignatius is building an Online Judge, now he has worked out all the problems except the Judge S ...
- BOS物流管理系统-第一天
BOS物流管理系统-第一天-系统分析.环境搭建.前端框架 BoBo老师 整体项目内容目标: 对项目概述的一些理解 亮点技术的学习 注意学习方式:优先完成当天代码. 其他内容. 最终: 学到新的技术,会 ...
- Recover the String
Recover the String 题目链接:http://codeforces.com/contest/709/problem/D 构造 这题乍一看很难构造,但是如果知道了整个字符串中'0'和'1 ...
- loadrunner 日志
loadrunner 日志包括两个部分 1.在VUGEN中运行后的日志,日志存放在脚本目录下output.log2.在controller中运行后的日志, result setting 设置目录 1. ...
- UITableView控制头部View
首先我们先集成一个UIView做一个自己的View #import <UIKit/UIKit.h> @interface MyView : UIView @property (nonato ...