Changing the default Java TimeZone does not work with createConnectionForPool

13 ビュー (過去 30 日間)
Emmanouil
Emmanouil 2020 年 1 月 10 日
編集済み: Allan Brett 2023 年 4 月 11 日
The problem is described as follows:
(1) I change the default Java TimeZone within MATLAB using the following command
java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone('UTC'));
(2) I initialize a parallel pool with JDBC Database Connection
c = createConnectionForPool( gcp , datasource , username , password )
(3) I run a parfor loop with fetch queries
parfor i = 1 : i_max
allresults{i} = fetch(c.Value,sqlqueries(i));
end
(4) The problem is that the time-data that i am fetching arrive with local TimeZone and not UTC as specified in step (1).
Step (1) is necessary for my script to overcome the issue described here:
Could you please assist me with the above?

回答 (2 件)

Andrew Janke
Andrew Janke 2020 年 1 月 31 日
Each of the workers in the Parallel Pool is a separate process with its own separate JVM. You need to run that java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone('UTC')); in each of your workers, and not just in your base Matlab session.

Allan Brett
Allan Brett 2023 年 4 月 11 日
編集済み: Allan Brett 2023 年 4 月 11 日
For anyone coming here because of the issue discussed here (https://www.mathworks.com/matlabcentral/answers/1468926-why-do-i-get-the-following-jdbc-driver-error-the-server-time-zone-value-cdt-is-unrecognized-or-r), but running into an issue with parallel pool database connections (createConnectionForPool). You need to manually set the connection options.
datasource = "some_source";
opts = databaseConnectionOptions(datasource);
opts = setoptions(opts,'URL','jdbc:mysql://127.0.0.1:3306/yoursever?serverTimezone='yourtimezonehere'');
saveAsDataSource(opts)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by