-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bulk Copy API does not perform Timezone conversion for DATETIME2(3) with PreparedStatement.setTimestamp #2271
Comments
Hi @PriyadharshiniP, We'll take a look at this, thank you. |
Hi @PriyadharshiniP, We're still in the process of exploring the issue. We have been able to reproduce so far though. A question we have: is it possible to use DateTimeOffset in your situation? DateTimeOffset inherently includes timezone information, and so would help avoid the situation you describe. |
Hi @Jeffery-Wasty |
Hi @PriyadharshiniP, Thank you for the update. We're currently working on fixing the above use case for DateTime2 with BulkCopy. |
Driver version
mssql-jdbc version 12.4.1.jre11
SQL Server version
Microsoft SQL Server 2019 (RTM-CU18) (KB5017593) - 15.0.4261.1 (X64) Sep 12 2022 15:07:06 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows 10 Pro 10.0 (Build 19045: )
Client Operating System
Windows
JAVA/JVM version
Java 17
Problem description
DATETIME2(3) type is supported by the Bulk Copy API. DATETIME2 is not there in the unsupported datatypes list as per: https://learn.microsoft.com/en-us/sql/connect/jdbc/using-bulk-copy-with-the-jdbc-driver?view=sql-server-ver16
Nevertheless, it was discovered that there appears to be NO timezone conversion with Bulk copy API for DATETIME2(3) column type.
The following is specified in the PreparedStatement.setTimestamp contract: "Sets the designated parameter to the given {@code java.sql.Timestamp} value,using the given {@code Calendar} object. The driver usesthe {@code Calendar} object to construct an SQL {@code TIMESTAMP} value, which the driver then sends to the database. With a {@code Calendar} object, the driver can calculate the timestamptaking into account a custom timezone. If no{@code Calendar} object is specified, the driver uses the default timezone, which is that of the virtual machine running the application."
Bulk copy API seems to ignore this calendar settings and inserts the timestamp value in the default timezone.
Please see the following stand alone Java code that inserts the first row WITHOUT bulk API and the second row WITH bulk API.
Actual behavior
The first row is inserted correctly without Bulk copy API.
As you can see, there is a problem with the second row that was put using the Bulk Copy API because the c3 value is utilizing the default time zone rather than GMT.
Expected behavior
The date entered in the third field using the stand alone program mentioned above should be changed to GMT timezone rather than the local timezone date value when using bulk copy API.
The c3 value for second row should also be "2023-12-04 00:43:29.000"
Error message/stack trace
No error happens.
The text was updated successfully, but these errors were encountered: