lanchengx commented on a change in pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#discussion_r728701953



##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) 
throws SQLException {
             ShardingSphereResource resource = 
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = 
resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", 
dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return 
dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       @roodkcab Thanks for your PR,could you use `try-with-resources`?
   More importantly, it may be necessary to copy the `ResultSet as` the return 
result, and then close the connection

##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName) 
throws SQLException {
             ShardingSphereResource resource = 
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = 
resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", 
dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return 
dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+            Connection conn = dataSourceEntry.get().getValue().getConnection();
+            try {
+                return conn.prepareStatement(sql).executeQuery();
+            } catch (SQLException e) {
+                throw e;
+            } finally {
+                conn.close();
+            }

Review comment:
       @roodkcab Thanks for your PR,could you use `try-with-resources`?
   More importantly, it may be necessary to copy the `ResultSet` as the return 
result, and then close the connection




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