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. 扩展Unity的方法

    写更少代码的需求 当我们重复写一些繁杂的代码,或C#的一些方法,我们就想能不能有更便捷的方法呢?当然在unity中,我们对它进行扩展. 对unity的类或C#的类进行扩展有以下两点要注意: 1.这个类 ...

  2. MVC,MVP 和 MVVM 的图示

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

  3. Nuget自己打包引用的时候出现错误:Package is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package 1.0.1 supports: net (.NETFramework,Version=v0.0)

    Nuget自己打包引用的时候出现错误:Package is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package ...

  4. sublime和python--path

    配置Sublime Text 2 的Python运行环境 (2013-09-11 11:36:17) 转载▼ 标签: python 分类: 科技相关     Sublime Text 2作为一款轻量级 ...

  5. Padrino 生成器指南

    英文版出处:http://www.padrinorb.com/guides/generators Padrino提供了用于快速创建应用的生成器,其优势在于构建推荐的Padrino应用结构.自动生成罗列 ...

  6. 将packages/apps/下的app导入eclipse

    当刚接触android自带的一个模块时,如何去熟悉它?相信不少人第一步都会尝试着去了解其内容的调用流程,而此时若能够单步调试则显得非常重要了,于是有了文章标题所说的尝试. 作者这里要导入的是Setti ...

  7. jboss CLI 命令行接口学习(适用JBOSS EAP 6.2+)

    一.确认CLI所使用的端口 以domain模式为例,查看domain controller(也就是master主机)上的host.xml <management-interfaces> & ...

  8. spring:如何用代码动态向容器中添加或移除Bean ?

    先来看一张类图: 有一个业务接口IFoo,提供了二个实现类:FooA及FooB,默认情况下,FooA使用@Component由Spring自动装配,如果出于某种原因,在运行时需要将IFoo的实现,则F ...

  9. K-means算法和矢量量化

    语音信号的数字处理课程作业——矢量量化.这里采用了K-means算法,即假设量化种类是已知的,当然也可以采用LBG算法等,不过K-means比较简单.矢量是二维的,可以在平面上清楚的表示出来. 1. ...

  10. IIS W3SVC 无法启动1068错误的解决

    苦苦寻找解决方法多天之后,终于看到了最简单的处理方法. 故障: 试遍网上各种方法,司马当活马,CMD下输入如下命令,然后重启: fsutil resource setautoreset true C: ...