java - 如何在SQL数据库日期列中插入空白值?

标签 java sql

我有一个数据库,其中有一列名为 START_TS,类型为(日期时间,不为空)。 我用 java 编写了一个程序,我想在该列中插入一个空白值,但它采取
“1900-01-01 00:00:00.000”作为值。

statement.executeUpdate("insert into tableName(START_TS) values(CAST(START_TS as varchar(100)))");

请建议我可以在该列中插入空白值的转换机制。

谢谢

最佳答案

如果您使用 MYSQL,其语法似乎指向;您可以执行以下操作:

ALLOW_INVALID_DATES

Do not perform full checking of dates. Check only that the month is in the range from 1 to 12 and the day is in the range from 1 to 31. This is very convenient for Web applications where you obtain year, month, and day in three different fields and you want to store exactly what the user inserted (without date validation). This mode applies to DATE and DATETIME columns. It does not apply TIMESTAMP columns, which always require a valid date.

This mode is implemented in MySQL 5.0.2. Before 5.0.2, this was the default MySQL date-handling mode. As of 5.0.2, the server requires that month and day values be legal, and not merely in the range 1 to 12 and 1 to 31, respectively. With strict mode disabled, invalid dates such as '2004-04-31' are converted to '0000-00-00' and a warning is generated. With strict mode enabled, invalid dates generate an error. To permit such dates, enable ALLOW_INVALID_DATES.

但是,就像每个人在评论中所说的那样,不可能在数据类型为 DATETIME 的字段中粘贴“”。

关于java - 如何在SQL数据库日期列中插入空白值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12274867/

相关文章:

sql - 使用 3 个表连接获取 API 列表

javascript - PHP/MySQL 查询按日期范围求和列

sql - 计算子组中的记录数,同时保留组中的许多记录

mysql - 使用 SELECT 查询结果计算不同值,但出现错误

c# - ServiceStack执行存储过程需要很长时间

java - 使用JavaFX在Eclipse中执行 "Hello Word"程序时出错

java - 期望 removeOnTabSelectedListener 表达式?

java - 可迭代的java列表循环并发问题

java - Hudson 使用错误的用户名创建文件

java - 如何以数组形式检索 JTable 数据