Skip to content
Advertisement

datetime conversion to Java in SQLServer 2016

I have a scenario where I have a table that has a date field with the datetime property.

In the documentation (https://learn.microsoft.com/en-us/sql/connect/jdbc/using-basic-data-types?view=sql-server-ver15) :

Note that java.sql.Timestamp values can no longer be used to compare values from a datetime column starting from SQL Server 2016. This limitation is due to a server-side change that converts datetime to datetime2 differently, resulting in non-equitable values. The workaround to this issue is to either change datetime columns to datetime2(3), use String instead of java.sql.Timestamp, or change database compatibility level to 120 or below.

I removed the use of timestamp, tried other solutions but none is working.

Could someone indicate any documentation or articles related to this scenario, please?

CarDAO :

JavaScript

mapCar

JavaScript

Generate a stack

JavaScript

tried other solution using Date and LocalDateTime but without success, can anyone share how they have already solved this problem in their implementations.

Edit :

public class Car { […] private final LocalDateTime createdAt; }

Advertisement

Answer

The solution was to change the date column to datetime2(3), I wanted to bypass it via the application, but given the need, the change was via the database.

ALTER TABLE SAJ.table DROP COLUMN myColumn;

ALTER TABLE SAJ.table ADD myColumndatetime2(3);

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement