@@ -125,7 +125,7 @@ protected MySQLInputConnection newConnection(PluginTask task) throws SQLExceptio
125
125
logConnectionProperties (url , props );
126
126
127
127
// load timezone mappings
128
- loadTimeZoneMappings ();
128
+ loadTimeZoneMappingsIfNeeded ();
129
129
130
130
Connection con = DriverManager .getConnection (url , props );
131
131
try {
@@ -145,7 +145,7 @@ protected ColumnGetterFactory newColumnGetterFactory(final PageBuilder pageBuild
145
145
return new MySQLColumnGetterFactory (pageBuilder , dateTimeZone );
146
146
}
147
147
148
- private void loadTimeZoneMappings ()
148
+ private void loadTimeZoneMappingsIfNeeded ()
149
149
{
150
150
// Here initializes com.mysql.jdbc.TimeUtil.timeZoneMappings static field by calling
151
151
// static timeZoneMappings method using reflection.
@@ -156,7 +156,11 @@ private void loadTimeZoneMappings()
156
156
// from the classloader. It seems like a bug of JDBC Driver where it should use the class loader
157
157
// that loaded com.mysql.jdbc.TimeUtil class rather than system class loader to read the
158
158
// property file because the file should be in the same classpath with the class.
159
- // Here implements a workaround as as workaround.
159
+ // Here implements a workaround as a workaround.
160
+ //
161
+ // This workaround seems required only for Connector/J 5.x (com.mysql.jdbc.TimeUtil),
162
+ // not necessary for Connector/J 8.x (com.mysql.cj.util.TimeUtil).
163
+ // TODO: Clarify for Connector/J 8.x just in case.
160
164
Field f = null ;
161
165
try {
162
166
Class <?> timeUtilClass = Class .forName ("com.mysql.jdbc.TimeUtil" );
@@ -172,7 +176,16 @@ private void loadTimeZoneMappings()
172
176
f .set (null , timeZoneMappings );
173
177
}
174
178
}
175
- catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException | IOException e ) {
179
+ catch (ClassNotFoundException e ) {
180
+ try {
181
+ Class .forName ("com.mysql.cj.util.TimeUtil" );
182
+ } catch (final ClassNotFoundException ex2 ) {
183
+ // Throw if neither the Connector/J 5.x nor 8.x driver is found.
184
+ throw new RuntimeException (e );
185
+ }
186
+ }
187
+ // Pass-through if the Connector/J 8.x driver is found. }
188
+ catch (IllegalAccessException | NoSuchFieldException | IOException e ) {
176
189
throw new RuntimeException (e );
177
190
}
178
191
finally {
0 commit comments