'0000-00-00 00:00:00' 不能表示为 java.sql.Timestamp 错误 [英] '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp error

查看:40
本文介绍了'0000-00-00 00:00:00' 不能表示为 java.sql.Timestamp 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含日期的数据库表

I have a database table containing dates

 (`date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'). 

我正在使用 MySQL.有时从程序中将没有日期的数据传递到数据库.因此,日期值会自动分配给 0000-00-00 00:00:00当使用日期列调用表数据时,它会出错

I'm using MySQL. From the program sometimes data is passed without the date to the database. So, the date value is auto assigned to 0000-00-00 00:00:00 when the table data is called with the date column it gives error

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

我在插入数据时试图将空值传递给日期,但它被分配给了当前时间.

I tried to pass null value to the date when inserting data, but it gets assign to the current time.

有什么办法可以在不改变表结构的情况下获得ResultSet?

Is there any way I can get the ResultSet without changing the table structure?

推荐答案

你可以直接在你的数据源配置中使用这个 JDBC URL:

You can use this JDBC URL directly in your data source configuration:

jdbc:mysql://yourserver:3306/yourdatabase?zeroDateTimeBehavior=convertToNull

jdbc:mysql://yourserver:3306/yourdatabase?zeroDateTimeBehavior=convertToNull

这篇关于'0000-00-00 00:00:00' 不能表示为 java.sql.Timestamp 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆