You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2021/03/08 03:54:43 UTC

[GitHub] [flink] wuchong commented on a change in pull request #15104: [FLINK-21635][connectors/jdbc] Support optional driverName in jdbc connection establishment

wuchong commented on a change in pull request #15104:
URL: https://github.com/apache/flink/pull/15104#discussion_r589155192



##########
File path: flink-connectors/flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/internal/connection/SimpleJdbcConnectionProvider.java
##########
@@ -100,7 +100,16 @@ private Driver getDriver() throws SQLException, ClassNotFoundException {
 
     @Override
     public Connection getOrEstablishConnection() throws SQLException, ClassNotFoundException {
-        if (connection == null) {
+        if (connection != null) {
+            return connection;
+        }
+        if (jdbcOptions.getDriverName() == null) {
+            connection =
+                    DriverManager.getConnection(
+                            jdbcOptions.getDbURL(),
+                            jdbcOptions.getUsername().orElse(null),
+                            jdbcOptions.getPassword().orElse(null));
+        } else {

Review comment:
       What about changing `getDriver()` to `getDriver(String driverName)` and check not null in the method? This can avoid `getDriver()` been used accidentally.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org