我有一个数据库,其中有一列名为 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/