使用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

我的问题是在添加时间类型的字段是,默认 0  ,所以导致不识别

can not be represented as java.sql.Timestamp相关推荐

  1. 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,默认为 ...

  2. 错误: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;刚开始 ...

  3. 关于Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp异常问题的解读

    前提 对于必传的字段, 新需求改为非必填的时候,在测试环境出现了 Value '0000-00-00 00:00:00' can not be represented as java.sql.Time ...

  4. java.sql.SQLException: 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 分析: ...

  5. 已解决:java.sql.SQLException: Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp

    一.问题 一大早到公司 Mysql 中的一个 datetime 字段时碰到了一个 Cause: java.sql.SQLException: Value '0000-00-00 00:00:00' c ...

  6. MySQL 错误【四】Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp

    1. 错误描述 在使用mysql时,如果数据库中的字段类型是timestamp,默认为0000-00-00,会发生异常:Value '0000-00-00 00:00:00' can not be r ...

  7. Cause: java.sql.SQLExceptioValue ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp

    今天使用mybatis创建demo测试的时候发现了一个有意思的bug org.apache.ibatis.exceptions.PersistenceException: ### Error quer ...

  8. Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp

    程序使用select 语句查询数据时,出现以下异常: java.sql.SQLException:Value '0000-00-00' can not be represented as java.s ...

  9. MySQL错误:Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp

    java项目,使用MySQL,字段类型为timestamp,字段值默认为0000-00-00 00:00:00. 在解析数据时会抛出一个异常: java.sql.SQLException: Value ...

最新文章

  1. 使用JS/Jquery获得父窗口的几个方法(笔记)
  2. cocos2dx中的背景图层CCLayerColor和渐变图层CCLayerGradient
  3. 派生类类型可以转换为基类类型,反之则不行
  4. 9款基于CSS3 Transitions实现的鼠标经过图标悬停特效
  5. Netty(三) 什么是 TCP 拆、粘包?如何解决?
  6. 【转】分享oldjun老大***网站的经验
  7. swoole中退出、异常与错误的处理笔记
  8. React-native集成tfs自动发版问题
  9. Linear Algebra - Determinant(几何意义)
  10. Windows 下的坐标系
  11. pc 浏览器最小字体12px
  12. 电阻电容封装买大了怎么办呢
  13. 计算机博弈 基础算法 阿尔法-贝塔剪枝算法 α-β剪枝算法
  14. Windows更新后双系统引导消失manjaro启动项丢失修复
  15. 3169: 小万的回文串
  16. js 树状图数组批量循环操作
  17. 视频直播美颜SDK算法代码解析
  18. 计算机存储介质清除工具,天桥科技存储介质信息消除工具
  19. 纯电动汽车整车控制器测试系统ETest综述
  20. 递归函数——上台阶问题

热门文章

  1. 用Audacity分析浊音、清音、爆破音的时域及频域特性
  2. 长生不老:从秦始皇到基因编辑
  3. android相册幻灯片功能,玩机教程 篇四十五:「MIUI玩机技巧63」MIUI相册新增“幻灯片播放”功能...
  4. js 日期格式转换为中文日期
  5. 学生学籍管理系统_登陆界面设计
  6. 手机打不开html,如何解决手机浏览器打不开网页的问题,原来是这样的
  7. 15 个百度网盘搜索引擎
  8. 生成随机字符串序列号类似于UUID,但是比较短的那种。
  9. U-Boot启动过程完全分析(转)
  10. Python正则表达式清洗微博文本特殊符号(网址, @, 表情符等)