turcsanyip commented on code in PR #10670:
URL: https://github.com/apache/nifi/pull/10670#discussion_r2635851403


##########
nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java:
##########
@@ -261,9 +265,13 @@ protected Driver getDriver(final String driverName, final 
String url) {
             return DriverManager.getDriver(url);
         } catch (final SQLException e) {
             // In case the driver is not registered by the implementation, we 
explicitly try to register it.
+            // deregister existing driver
             try {
-                final Driver driver = (Driver) 
clazz.getDeclaredConstructor().newInstance();
-                DriverManager.registerDriver(driver);
+                if (registeredDriver != null) {
+                    DriverManager.deregisterDriver(registeredDriver);
+                }
+                registeredDriver = (Driver) 
clazz.getDeclaredConstructor().newInstance();

Review Comment:
   Modern JDBC drivers use Java's Service Loader mechanism to load the driver 
class automatically. Manual instantiation is rarely required and this code in 
the catch block is more of a ‘just-in-case’ fallback.
   
   May I ask what JDBC driver are you using that requires manual loading?
   
   I'm afraid, we cannot control the automatically registered drivers. 
Therefore, even if we add a deregistration mechanism for the manual-loading 
case, the issue would still persist for the majority of the use cases.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to