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 ...
随机推荐
- netty初探(2)
上一篇 netty(1) 一.TCP/IP 流式传输 在上文演示了2进制流式传输引起的TCP拆包问题,这里继续演示文本型的传输问题,文本型的可以有以下几种策略 1.1 以特殊字符表示结尾 HTTP协议 ...
- 给go添加各种package
go version 1.1.2 For example you need to install the webscoket pakeage try go get code.goo ...
- matlab里plot画多幅图像、设置总标题、legend无边框
%%绘图 suptitle('公路') %总标题subplot(2,2,1);plot(x,y11,'r-') hold onplot(x,y21,'b-')xlabel('方向')ylabel(' ...
- c#代码发送post请求,上传文件(并带其他参数)
本人对post理解不深,前段时间遇到一个需要用c#代码发送post请求上传文件的业务,于是参考了几篇帖子,加上自身实践写出了如下代码.写的比较low 望各位大大指正^_^. 业务需求: 对方给了一个接 ...
- List<T>集合导出csv方法参考,通过增加自定义的属性控制输出的字段。
public string CreateAdvExcel(List<GridScoreManager> lt) { StringBuilder builder = new StringBu ...
- lvs 会话保持(转发)
lvs & keepalived的tcp 长连接的问题解决办法 虽然应用keepalived搞定了后端服务负载均衡和高可用性问题,但是在具体应用的时候,还是要注意很多问题.很多应用都用tcp或 ...
- 5. test命令
Shell中的 test 命令用于检查某个条件是否成立,它可以进行数值.字符和文件三个方面的测试. 1. 数值测试 参数 说明 -eq 等于则为真 -ne 不等于则为真 -gt 大于则为真 -ge 大 ...
- git clone出现SSL错误
在学习git的时候,发现不能使用git clone从github.com下载,报了个ssl错误. Cloning into cancan... error: SSL certificate probl ...
- UITableViewCell上面添加UIWebView
首先创建一个webView对象和 private var webViewcell : UIWebView? 在viewDidLoad里面设置创建webViewcell,设置属性并用kvo监听webVi ...
- 数据库还原失败System.Data.SqlClient.SqlError: 无法执行 BACKUP LOG,因为当前没有数据库备份
结尾日志的问题 还原选择中去掉结尾日志就可以了 转载自:http://blog.csdn.net/aojiancc2/article/details/46316451