简体   繁体   中英

How to insert blank value in SQL database date column?

I have one database in which there is one column named START_TS of type (datetime,not null). I wrote one program in java where I want to insert a blank value in that column but its taking
'1900-01-01 00:00:00.000' as the value.

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

Please suggest the casting mechanism where i can insert blank value in that column.

Thanks

If you using MYSQL which the syntax appears to point at; you could do the following:

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.

However like everyone has said in the comments, it's not possible to stick a " " in a field whose data type is DATETIME.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM