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
Handling of datetime is flawed #339
Comments
Hi @jedvardsson , thank you for providing these details. We will have to dig into this a bit more. We are currently working to stabilize the code base to release and we'll circle back to this issue once that's complete. |
Hi @jedvardsson, thank you for raising this issue this us. We investigated your problem as above, but it doesn't look an ideal solution to provide different values when retrieved by different functions: As per JDBC specs (since 2.0), The workaround mentioned by you is intended for advanced globalization uses only and is not recommended. As the function
From driver's perspective, we shall continue to follow JDBC Specs such that Let us know if you have any further queries. |
Hi @jedvardsson would like to know your views if you got chance to read my comment above. |
Hi @cheenamalhotra , Thank you for taking your time and looking into this issue. I understand your point about not updating Secondly, I don't understand your point about And that is what I am doing: calling Let me know if I understood you correctly. Thanks. |
Hi @jedvardsson, Thanks for writing back. I agree with you for the workaround, calling I am glad to know we both are on the same page and you agree we must not update |
The way that
datetime
is handled by mssql-jdbc is flawed.datetime
types are time-zoneless, however, the driver maps them to the JVM time zone when deserializing thedatetime
sent from SQLServer.The test program below shows what happens when reading the output of
select cast('2017-03-26T02:00:00' as datetime2)
.When running the program in UTC all is working nicely.
However, in Europe/Stockholm (or CET) things fails.
Obviously this comes down to that
2017-03-26T02:00:00
in Europe/Stockholm falls just on the start of the DST gap. The driver internally converts the local date time to a zoned date time usingjava.util.Calendar
andjava.sql.Timestamp
. Those classes can't work with truly local date times since they automatically move date times inside gaps to the next non-gap datetime which is2017-03-26T03:00:00
.The problem is that local date times are linear:
2017-03-26T01:59:59
is2017-03-26T02:00:00
While zoned date times are non-linear (because of how they are mapped on to UTC):
2017-03-26T01:59:59
is2017-03-26T03:00:00
.Therefore we can't use java.util.Calendar and java.sql.Timestamp to represent local date times correctly unless we work in UTC. For other time zones the conversion between local data times -> zoned date times -> local date times is destructive.
A workaround in application code is to replace the call
r.getTimestamp(1).toLocalDateTime()
above with the more complex:Note that database IDE:s with database integrations such as IntelliJ or DbVisualizer aren't aware of this. They simply call
ResultSet.getObject()
. For example, the result of the below queryis displayed like this in IntelliJ (in fact, this was how I spotted the problem in the first place).
getObject()
returns a String and not a Timestamp.I understand that the problem here is bigger then the mssql-jdbc and that it comes down to JDBC and its use of the old legacy classes Calendar and Timestamp. However, maybe mssql-jdbc can work with date times (and such types) in an internal format so that e.g.
getTimestamp()
keeps its old behavior and thatgetObject()
returns aLocalDateTime
?The text was updated successfully, but these errors were encountered: