can not be represented as java.sql.Timestamp
来源:互联网 发布:淘宝客采集软件有哪些 编辑:程序博客网 时间:2024/06/08 11:46
今天升级项目,启动时报错can not be represented as java.sql.Timestamp
使用hibernate开发程序的时候,有的时间字段没有必要填写,但是,以后hibernate查询的时候会报出
“java.sql.SQLException: Value ‘0000-00-00’ can not be represented as java.sql.Timestamp”
的错误, 这是因为hibernate认为这个不是一个有效的时间字串。
而有效的日期格式为“ 0001-01-01 00:00:00.0 ”
查看了mysql5的帮助文档对于datetime的解释如下
Datetimes with all-zero components (0000-00-00 …) — These values can not be represented 关于所有Datetime类型由0组成的数据,这些值不能在java中被可靠的表示
reliably in Java.
Connector/J 3.0.x always converted them to NULL when being read from a ResultSet.
当这些值正在从ResultSet容器中读取时候,Connector/J 3.0.x 一直把他们转换为NULL值。
Connector/J 3.1 throws an exception by default when these values are encountered as this is the most correct behavior according to the JDBC and SQL standards.
依照JDBC和SQL的标准这些值碰到的最正确的处理方式就是在缺省情况下产生异常
This behavior can be modified using the zeroDateTimeBehavior configuration property. The allowable values are:
JDBC允许用下列的值对zeroDateTimeBehavior 属性来设置这些处理方式,
exception (the default), which throws an SQLException with an SQLState of S1009.
设置为exception 异常(缺省)用一个SQLState的s1009错误号来抛出一个异常
convertToNull, which returns NULL instead of the date.
设置为convertToNull,用NULL值来代替这个日期类型
round, which rounds the date to the nearest closest value which is 0001-01-01.
设置为round,则围绕这个日期最接近的值(0001-01-01)来代替
修改你的jdbc连接
jdbc:mysql://localhost/schoolmis?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
- can not be represented as java.sql.Timestamp
- can not be represented as java.sql.Timestamp
- can not be represented as java.sql.Timestamp
- can not be represented as java.sql.Timestamp
- can not be represented as java.sql.Timestamp
- can not be represented as java.sql.Timestamp
- Err:java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Timestamp
- [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.Timestamp
- “java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Timestamp”
- java.sql.SQLException: Value '[B@8ea6b9' can not be represented as java.sql.Timestamp
- java Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
- Value '0000-00-00' can not be represented as java.sql.Timestamp
- Value '0000-00-00' can not be represented as java.sql.Timestamp错误
- mysql Value '0000-00-00' can not be represented as java.sql.Timestamp
- Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
- mysql抛出Value '0000-00-00' can not be represented as java.sql.Timestamp异常
- '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp error
- (求DAG图最长路)拓扑排序模板
- JSON入门Java篇-3-用json.org来构建JSON数据并输出
- 在JSP页面中显示JavaBean属性信息
- hdu 6007 Mr. Panda and Crystal(最短路+完全背包)
- [译]我的go语言使用场景
- can not be represented as java.sql.Timestamp
- Java学习第五课
- 《程序设计入门—Java语言.翁恺》第二周编程作业(1)-时间转换
- 671. Second Minimum Node In a Binary Tree
- bat面试题 python 单链表反转排序
- 接口,继承的意义和使用方法
- 成为Java顶尖程序员 ,看这11本书就够了 以下是我推荐给Java开发者们的一些值得一看的好书。但是这些书里面并没有Java基础、Java教程之类的书,不是我不推荐,而是离我自己学习 Java基础技
- Tensorflow学习笔记(三)--变量作用域
- linux系统基本命令之文件和目录管理及vim,正则表达式