I have a table with a column that is a DATETIME in a SQL Server 2008 database. The dates that are being inserted are not timestamps in the sense that using NOW on insert would be acceptable. The date is generated a bit before the insert and I would like to preserve this value.
Datetimes are being serialized as strings in the format yyyy-mm-dd hh:mm:ss.[fff...] and then converted to a JDBC Timestamp object before being inserted.
A problem I’m running into with SQL Server is that it converts the value to TIMESTAMP before being inserted and then complains with this:
com.microsoft.sqlserver.jdbc.SQLServerException:
Cannot insert an explicit value into a timestamp column.
Use INSERT with a column list to exclude the timestamp column,
or insert a DEFAULT into the timestamp column.
How can I just insert into a DATETIME column without the conversion?
Thanks.
A SQL Server TIMESTAMP data type is not a date-like data type. It is a server-generated value used to help with data consistency. If you are storing datetime data, then avoid the TIMESTAMP data type.
So, don’t convert to a JDBC Timestamp object. Data can be inserted as a string value. Note that the format you indicate is okay, but the
fff...must be 3 digits, not more than 3 digits for a SQL Server DATETIME data type.