Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected MySQLInputConnection newConnection(PluginTask task) throws SQLExceptio
logConnectionProperties(url, props);

// load timezone mappings
loadTimeZoneMappings();
loadTimeZoneMappingsIfNeeded();

Connection con = DriverManager.getConnection(url, props);
try {
Expand All @@ -145,7 +145,7 @@ protected ColumnGetterFactory newColumnGetterFactory(final PageBuilder pageBuild
return new MySQLColumnGetterFactory(pageBuilder, dateTimeZone);
}

private void loadTimeZoneMappings()
private void loadTimeZoneMappingsIfNeeded()
{
// Here initializes com.mysql.jdbc.TimeUtil.timeZoneMappings static field by calling
// static timeZoneMappings method using reflection.
Expand All @@ -156,7 +156,10 @@ private void loadTimeZoneMappings()
// from the classloader. It seems like a bug of JDBC Driver where it should use the class loader
// that loaded com.mysql.jdbc.TimeUtil class rather than system class loader to read the
// property file because the file should be in the same classpath with the class.
// Here implements a workaround as as workaround.
// Here implements a workaround as a workaround.
//
// It's not 100% sure, but this workaround is necessary for Connector/J 5.x (com.mysql.jdbc.TimeUtil)
// only.
Field f = null;
try {
Class<?> timeUtilClass = Class.forName("com.mysql.jdbc.TimeUtil");
Expand All @@ -172,7 +175,11 @@ private void loadTimeZoneMappings()
f.set(null, timeZoneMappings);
}
}
catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException | IOException e) {
catch (ClassNotFoundException e) {
// It appears that the user uses the Connector/J 8.x driver.
// Do nothing;
}
catch (IllegalAccessException | NoSuchFieldException | IOException e) {
throw new RuntimeException(e);
}
finally {
Expand Down