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. ADO.NET防止字符串攻击方法

    在黑窗口里面输入内容时利用拼接语句可以对数据进行攻击 如:输入班级值 --:代表后边内容都被注释掉了 防止SQL注入攻击方法: 再给命令发送SQL语句的时候分两次发送,把SQL语句拆成两块,用户输入的 ...

  2. Beanstalk消息队列的实现

    在工作中要用到消息队列,但是主管为了追求开发速度,让用了一个简易的类  beanstalk 下面来说明这个东西 参考博客:https://my.oschina.net/u/698121/blog/15 ...

  3. java 24 - 2 GUI之监听机制和适配器改进窗口关闭

    我们创建了窗体后,就要对窗体进行操作,比如关闭窗口.而这时候就要建立监听机制: 事件监听机制: A:事件源 事件发生的地方 B:事件 就是要发生的事情 C:事件处理 就是针对发生的事情做出的处理方案 ...

  4. linux下内网端口转发工具:linux版lcx [实现远程内网维护]

    这个工具以前使用的初衷是内网渗透,需要将内网ssh端口转发到外网服务器上.但这个工具同样适用于运维工程师进行远程内网维护. 当然这一切的前提是内网可以访问外网,检测方法当然就是直接ping 一个外网I ...

  5. java(搜索不区分大小写)

    ref.put("myfield", Pattern.compile(".*myValue.*" , Pattern.CASE_INSENSITIVE));

  6. MVC,MVP 和 MVVM 的图示

    作者: 阮一峰 日期: 2015年2月 1日 复杂的软件必须有清晰合理的架构,否则无法开发和维护. MVC(Model-View-Controller)是最常见的软件架构之一,业界有着广泛应用.它本身 ...

  7. StringBuffer and StringBuilder

    As of release JDK 5, this class has been supplemented with an equivalent class designed for use by a ...

  8. POJ 3714 Raid

    Description After successive failures in the battles against the Union, the Empire retreated to its ...

  9. NOI2018准备Day3

    noip2016成绩出来了,199,268名 noip2017需要考过6个女生才能进省队,不包括明年会突然跳出来的大神...... 今天晚上玩了一晚上,做了2道题. 这事儿只干今晚一次

  10. VMware Fusion 中如何复制centos/linux虚拟机

    今天想在mac本上,弄几个centos的虚拟机,尝试搭建hadoop的全分布环境.一台台虚拟机安装过去太麻烦了,想直接将现有的centos虚拟机复制几份完事,但是复制出来的虚拟机无法上网,折腾了一翻, ...