使用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. open AI 在DOTA 5v5 比赛中战胜职业选手
  2. aptitude安装出现依赖_oeasy 教您玩转linux 之 010210 应用管理 aptitude
  3. Python——列表中存放字典遇到的问题
  4. ArrayList单列集合的简单使用常见方法
  5. Hemberg-lab单细胞转录组数据分析(九)- Scater包单细胞过滤
  6. python包含html5么_Python3 集合
  7. u-boot源码配置原理分析
  8. 挫败帆船行业调研报告 - 市场现状分析与发展前景预测(2021-2027年)
  9. 使用idea的的第一个坑-----javax.xml.ws.WebServiceRef
  10. 区块链应用大数据的优势有哪些
  11. 新中大财务软件V5.08安装
  12. bzoj 4816 数字表格 —— 反演
  13. 安装ADOBE READER时无法将数值写入键_php_sir_新浪博客
  14. Kaggle Kernels使用方法
  15. GitLab设置受保护的分支
  16. Mysql数据库基础知识总结,结构分明,内容详细
  17. 洛谷P1605 迷宫(dfs) 题解
  18. 十余种漂亮照片边框简单制作技巧
  19. History lives on in this distinguished Polish city 2017/1/4
  20. 机器人行业中我们常说的roll、yaw、pitch是什么?

热门文章

  1. EXCEL横向表格如何调整为纵向表格?
  2. random用法 python_python:random用法
  3. PostgreSQL:不支持 10 验证类型
  4. [java] JDBC数据库编程
  5. 如何使用 DiskGenius 合并分区教程
  6. SpringBoot-注解日志 Aop注解切入点
  7. Kaldi简介【开源语音识别工具】
  8. 2033-人见人爱A+B(java)
  9. Android7.0适配
  10. 树莓派4B之火焰传感器模块(python3)