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

原创 2016年05月30日 10:21:20

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参数:

jdbc:mysql://192.168.1.202:3306/com?autoReconnect=true&useUnicode=true&characterset=utf8mb4&zeroDateTimeBehavior=convertToNull 
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

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

处理Sql查询遇到这样一个问题(数据库是MySQL),有个字段定义类型是datetime,且非空无默认值, 通过PHPMyAdmin界面填充测试数据的时候没有理会这个字段,看到个小警告,插入成功...

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

1、错误描述### Cause: java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date ;...

MySQL 关于 Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestam

MySQL 关于 Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestam 博客分类:  MySQL ...
  • lkx94
  • lkx94
  • 2016年12月07日 14:45
  • 304

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

详细错误信息:org.springframework.dao.TransientDataAccessResourceException: ### Error querying database. ...

mysql数据库中日期类型为datetime,而用mybatis映射失败,报java.sql.SQLException: Cannot convert value '0000-00-00 00:00:

环境:mysql数据库+mybatis mysql的某个字段为日期,它的类型用的是datetime。然后框架用mybatis,然后查询的时候进行映射操作是报 java.sql.SQLE...

java.io.FileNotFoundException: Template /template/SEL00/token.ftl not found. <s:token>出错

java.io.FileNotFoundException: Template /template/SEL00/token.ftl not found. at freemarker.template...

android之“java.lang.IllegalArgumentException: Window type can not be changed after the window is add”

异常详情: 08-11 10:33:16.720: E/AndroidRuntime(16778): FATAL EXCEPTION: main 08-11 10:33:16.720: E/Andr...

Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!

web项目执行查询的时候报错: Caused by: java.sql.SQLException: Connections could not be acquired from the underl...

java.sql.SQLException: Can not issue empty query.

1、错误描述 java.sql.SQLException: Can not issue empty query. at com.mysql.jdbc.SQLError.createSQLExcept...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Value '0000-00-00' can not be represented as java.sql.Date
举报原因:
原因补充:

(最多只允许输入30个字)