Mysql开发中采用ResultSet取值時,不管是才用getString()还是用getDate(),或者getObject,均会拋出如题所述异常.查阅Mysql官方Bug咨询:

是因为日期型(Date或DateTime类型)字串为'000-00-00'时,MySQL预设处理方式是拋出异常(exception).只要将jdbc数据库连接字串作如下修改即可:

修改前jdbc连接字符串为:

jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8&characterSetResults=UTF-8

修改後jdbc连接字符串为 :

 jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull

原文如下:

Datetimes with all-zero components (0000-00-00 ...) — These values can not be represented reliably in Java. Connector/J 3.0.x always converted them to NULL when being read from a ResultSet.

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. This behavior can be modified using the zeroDateTimeBehavior configuration property. The allowable values are:

exception (the default), which throws an SQLException with an SQLState of S1009.

convertToNull, which returns NULL instead of the date.

round, which rounds the date to the nearest closest value which is 0001-01-01.

Starting with Connector/J 3.1.7, ResultSet.getString() can be decoupled from this behavior via noDatetimeStringSync=true (the default value is false) so that you can retrieve the unaltered all-zero value as a String. It should be noted that this also precludes using any time zone conversions, therefore the driver will not allow you to enable noDatetimeStringSync and useTimezone at the same time.

mssql-异常value '0000-00-00' can not be represented as java.sql.Date的更多相关文章

  1. 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 页面中,时间字段类型为空的信息显示不出来,且报错信息如下: ...

  2. '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 ...

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

  4. 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 ...

  5. 报错 java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp 原因

    sql异常 java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestam ...

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

  7. Caused by: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

    错误信息如下: Caused by: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java ...

  8. 报错:java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

    感谢原文作者:风起云淡- 原文链接:https://blog.csdn.net/shenguan777/article/details/78615521 异常分析: 在使用MySql时,如果数据库中有 ...

  9. mysql查表的时候报错:java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timest

    在spark项目中读取mysql中的数据的时候,发生了报错: 原因:主要是因为数据库中有一些字段为null,无法进行转换: 上面字段那种,我的inserttime字段类型为timestamp类型,不为 ...

  10. Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

    1.问题场景描述:后台方法中执行查询返回list列表中,执行后台产生运行时异常 java.sql.SQLException: 2.问题排查和解决:排查代码,无编译时错误,断点调试,更具控制台找到对应的 ...

随机推荐

  1. UIPanelResetHelper(UIScrollView滚动复位)

    原理 如果我们的UI中有滑动列表,并且列表比较长,那么不知道你们是否有这样需求,每次页面打开时,列表的滑动状态都恢复到默认状态. 如果要复位,其实就是修改UIPanel 的属性到初始状态.此组件做的工 ...

  2. java 22 - 13 多线程之解决线程安全问题的实现方式2

    上一章说了,解决线程安全问题的实现方式1是使用同步代码块 同时也知道了,同步代码块的锁对象是任意对象:(Object obj ;  Demo d;)这些都行 那么,现在来说解决线程安全问题的实现方式2 ...

  3. 手写PHP AJAX数据脚本

    <script type="text/javascript"> var xmlrequest = ""; function getXMLreques ...

  4. hadoop: hbase1.0.1.1 伪分布安装

    环境:hadoop 2.6.0 + hbase 1.0.1.1 + mac OS X yosemite 10.10.3 安装步骤: 一.下载解压 到官网 http://hbase.apache.org ...

  5. TinyFrame升级之九:实现复杂的查询

    本章我们主要讲解如何实现一个复杂的查询.由于目前TinyFrame框架已经投入到了实际的项目生产中,所以我很乐意将项目中遇到的任何问题做以记录并备忘. 这章中,我们提到的查询界面如下所示: 其中,涉及 ...

  6. java实战之解析xml

    在java中解析xml有现成的包提供方法,常用的有四类:Dom,JDom,Sax以及Dom4j.其中前者是java中自带的,后三者需要大家从开源诸如sourceforge这样的网站下载jar包,然后在 ...

  7. 套用GGTalk做项目的经验总结——GGTalk源码详解系列(一)

    坦白讲,我们公司其实没啥技术实力,之所以还能不断接到各种项目,全凭我们老板神通广大!要知道他每次的饭局上可都是些什么人物! 但是项目接下一大把,就凭咱哥儿几个的水平,想要独立自主.保质保量保期地一个个 ...

  8. Mininet的内部实现原理简介

    原文发表在我的博客主页,转载请注明出处. 前言 之前模拟仿真网络一直用的是Mininet,包括写了一些关于Mininet安装,和真实网络相连接,Mininet简历拓扑的博客,但是大多数都是局限于具体步 ...

  9. Altera SoC与Matlab的联合---第一步 软件安装与硬件测试

    参考设计:http://cn.mathworks.com/help/hdlcoder/examples/getting-started-with-hardware-software-codesign- ...

  10. 5-touch 命令总结