Skip to content
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

Add support for a serverTimeZone property #605

Closed
wants to merge 5 commits into from

Conversation

kkofler
Copy link

@kkofler kkofler commented Jan 16, 2018

The serverTimeZone property can be passed in the connection string and
allows globally setting a time zone, which is used for all date and time
conversions where no Calendar is explicitly specified, instead of using
the client JVM's time zone. Having this option set explicitly in all
clients ensures that they all agree on the time zone to use,
independently of what their default time zone is.

Forcing serverTimeZone to UTC even also helps if the database contains
times in more than one time zone, because UTC has no invalid time
ranges, so no information is lost converting between a time with
unspecified time zone and a time stamp in UTC.

Some other JDBC drivers (e.g., MySQL Connector/J and MariaDB
Connector/J) also have such an option.

The serverTimeZone property can be passed in the connection string and
allows globally setting a time zone, which is used for all date and time
conversions where no Calendar is explicitly specified, instead of using
the client JVM's time zone. Having this option set explicitly in all
clients ensures that they all agree on the time zone to use,
independently of what their default time zone is.

Forcing serverTimeZone to UTC even also helps if the database contains
times in more than one time zone, because UTC has no invalid time
ranges, so no information is lost converting between a time with
unspecified time zone and a time stamp in UTC.

Some other JDBC drivers (e.g., MySQL Connector/J and MariaDB
Connector/J) also have such an option.
@msftclas
Copy link

msftclas commented Jan 16, 2018

CLA assistant check
All CLA requirements met.

@codecov-io
Copy link

codecov-io commented Jan 16, 2018

Codecov Report

Merging #605 into dev will decrease coverage by 0.11%.
The diff coverage is 33.9%.

Impacted file tree graph

@@             Coverage Diff              @@
##                dev     #605      +/-   ##
============================================
- Coverage     48.79%   48.67%   -0.12%     
+ Complexity     2824     2811      -13     
============================================
  Files           118      118              
  Lines         27877    27878       +1     
  Branches       4642     4643       +1     
============================================
- Hits          13602    13570      -32     
- Misses        12086    12116      +30     
- Partials       2189     2192       +3
Flag Coverage Δ Complexity Δ
#JDBC42 48.18% <33.9%> (-0.15%) 2769 <45> (-14)
#JDBC43 48.61% <33.9%> (-0.08%) 2809 <45> (-9)
Impacted Files Coverage Δ Complexity Δ
...ncurrentlinkedhashmap/ConcurrentLinkedHashMap.java 38.85% <ø> (-0.16%) 42 <0> (-1)
...om/microsoft/sqlserver/jdbc/SQLServerResource.java 100% <ø> (ø) 4 <0> (ø) ⬇️
...om/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java 52.52% <0%> (-0.13%) 264 <0> (-2)
.../microsoft/sqlserver/jdbc/SQLServerDataSource.java 45.12% <0%> (-0.45%) 66 <0> (ø)
...rc/main/java/com/microsoft/sqlserver/jdbc/DDC.java 44.9% <100%> (-1.52%) 109 <22> (-1)
.../com/microsoft/sqlserver/jdbc/SQLServerDriver.java 80.36% <100%> (+0.13%) 25 <0> (ø) ⬇️
...ooglecode/concurrentlinkedhashmap/LinkedDeque.java 27.13% <26.4%> (-0.57%) 19 <18> (ø)
...in/java/com/microsoft/sqlserver/jdbc/IOBuffer.java 55.96% <64.7%> (-0.04%) 0 <0> (ø)
.../microsoft/sqlserver/jdbc/SQLServerConnection.java 48.13% <66.66%> (+0.03%) 336 <1> (+1) ⬆️
...l/googlecode/concurrentlinkedhashmap/Weighers.java 8.69% <8.69%> (+0.36%) 1 <1> (ø) ⬇️
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02467eb...fe77ea1. Read the comment docs.

@kkofler
Copy link
Author

kkofler commented Jan 16, 2018

For the CLA, I am waiting for the official OK from my employer.

@kkofler
Copy link
Author

kkofler commented Jan 16, 2018

CLA now on file, my employer OKed it.

@cheenamalhotra cheenamalhotra added this to Under Investigation in MSSQL JDBC Feb 9, 2018
@gordthompson
Copy link
Contributor

@cheenamalhotra - Related to #749 ...?

@ulvii ulvii added this to the 7.1.4 milestone Dec 4, 2018
@ulvii ulvii self-assigned this Dec 4, 2018
@ulvii
Copy link
Contributor

ulvii commented Dec 10, 2018

Hi @kkofler,

The methods that let you specify Calendar explicitly already provide the functionality you are asking for. That being said, are there any date/time APIs that do not have an alternative with Calendar support? If that's the case, please let us know, we might consider adding it.

@kkofler
Copy link
Author

kkofler commented Dec 10, 2018

Unfortunately, always explicitly specifying the Calendar is not really a practical option when working with an abstraction layer such as Hibernate.

@ulvii
Copy link
Contributor

ulvii commented Dec 10, 2018

@kkofler,

Looks like Hibernate 5.3 has a property called hibernate.jdbc.time_zone that invokes the methods with Calendar support. Please give it a try.

@ulvii
Copy link
Contributor

ulvii commented Dec 18, 2018

Closing the PR as the driver already provides the requested functionality with Calendar. @kkofler, please let us know if you have any concerns. Please also feel free to create PRs, we appreciate contributions from community.

@ulvii ulvii closed this Dec 18, 2018
MSSQL JDBC automation moved this from Under Investigation to Closed/Merged PRs Dec 18, 2018
@Savers80
Copy link

Savers80 commented Oct 9, 2019

@ulvii i think the solution of use property hibernate.jdbc.time_zone is valid only if use Hibernate
However if the application use hibernate and you can config hibernate property in case you have more jdbc database connection you cannot specify time _zone for one specific database; all database must use same time_zone; i.e db1 store datetime as GMT and JVM use user.timeZone=GMT, db2 used from third-party application stores datetime as UTC+2

In case you don't use hibernate or you can't modify hibernate configuration per single database (i.e third-party application "Appian" ) and you can't manage this scenario

I think pull #749 is not related to this feature serverTimeZone
i.e JavaApplication1 that use JVM time zone GMT that acces to another database db2 where datetime are stored in UTC+2 , convert java date time at 00:00 GMT into database side 02:00 UTC+2
Using the requested property 'serverTimeZone=UTC+2' in this scenario the above conversion musto no take place and query filtering will consider java side 00:00 GMT as database side 00:00 UTC+2

Hope reconsider to add support for a serverTimeZone property
Or suggest a solution for the scenario showed , without modify java code of thirty Part Application, or modify/implement database view

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
MSSQL JDBC
  
Closed/Merged PRs
Development

Successfully merging this pull request may close these issues.

None yet

7 participants