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

问题描述, 在java应用程序中,数据表中有记录的time字段(属性为timestamp)其值为:“0000-00-00 00:00:00”

程序使用select 语句从中取数据时出现以下异常:

java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date

这是因为 “0000-00-00 00:00:00”在mysql中是作为一个特殊值存在的,但是在Java中, java.sql.Date 会被视为 不合法的值,被JVM认为格式不正确。

解决办法:

在jdbc的url加上   zeroDateTimeBehavior参数:

datasource.url=jdbc:mysql://localhost:3306/pe?useUnicode=true&characterEncoding=gbk&zeroDateTimeBehavior=convertToNull

对于值为0000-00-00   00:00:00(默认值)的纪录,根据不同的配置,会返回不同的结果:

不配置:默认返回异常

zeroDateTimeBehavior=round   0001-01-01   00:00:00.0

zeroDateTimeBehavior=convertToNull   null

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. Value '0000-00-00' can not be represented as java.sql.Date

    Value '0000-00-00' can not be represented as java.sql.Date 时间 2014-07-30 09:00:50 ITeye-博客 原文  http: ...

  3. Java:出现错误提示(java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date)

    Java:出现错误提示(java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date) 原因分析: ...

  4. 问题解决:java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date

    问题描述: 数据表中有记录的time字段(属性为timestamp)其值为:“0000-00-00 00:00:00” 程序使用select 语句从中取数据时出现以下异常: Java.sql.SQLE ...

  5. mssql-异常value '0000-00-00' can not be represented as java.sql.Date

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

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

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

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

随机推荐

  1. JS基础_JS的HelloWorld

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. Linux Exploit系列之一 典型的基于堆栈的缓冲区溢出

    Linux (x86) Exploit 开发系列教程之一(典型的基于堆栈的缓冲区溢出) Note:本文大部分来自于看雪hackyzh的中文翻译,加入了一些自己的理解 典型的基于堆栈的缓冲区溢出 虚拟机 ...

  3. Python多线程异步任务队列

    原文地址 python的多线程异步常用到queue和threading模块 #!/usr/bin/env python # -*- coding: UTF-8 -*- import logging i ...

  4. Java的clone方法

    现在有User类:(Getter和Setter省略) public class User implements Cloneable { private String name; private int ...

  5. 韦东山嵌入式Linux学习笔记03--如何搭建软件环境

    1. 从网上下一个虚拟机,比如vmvare station 2.下一个ubuntu镜像回来安装,  我下了14.04来安装.参考链接:  https://blog.csdn.net/qq1326702 ...

  6. poj 2081 Recaman's Sequence (dp)

    Recaman's Sequence Time Limit: 3000MS   Memory Limit: 60000K Total Submissions: 22566   Accepted: 96 ...

  7. 在哪里查看java的jar包版本?

    jar包根目录里的META-INF目录下的MANIFEST.MF文件里一般有会记录版本信息,可以到这个文件里查看 .

  8. 给DataFrame的列命名或重命名

    1.读取文件的时候重命名 names = new_col,可以在读取文件的时候,给出新列名. new_col = ['new1', 'new2',... , 'newn'] pd.read_csv(' ...

  9. 说一说你对HTML5语义化的理解

    本题地址:https://github.com/YvetteLau/Step-By-Step/issues/8 语义化意味着顾名思义,HTML5的语义化指的是合理使用语义化的标签来创建页面结构,如he ...

  10. js 百分比显示页面加载进度

    做东西遇到显示页面百分比的加载进度,不过里面的图片较多,看了别人的代码,才想到可以通过图片的加载显示加载的百分比,做一下笔记: html: <span id="percent" ...