From 346b85d54bb46245a68cdacb7b395aa00c682273 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 20 Aug 2024 13:37:48 +0200 Subject: [PATCH] Make sure that we auto close the JDBC Connection and Statement when executing a schema resource --- .../impl/db/AbstractSqlScriptBasedDbSchemaManager.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/AbstractSqlScriptBasedDbSchemaManager.java b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/AbstractSqlScriptBasedDbSchemaManager.java index 523c03de75e..fae4060db23 100644 --- a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/AbstractSqlScriptBasedDbSchemaManager.java +++ b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/AbstractSqlScriptBasedDbSchemaManager.java @@ -248,8 +248,7 @@ protected void executeSchemaResource(String operation, String component, String String sqlStatement = null; String exceptionSqlStatement = null; DbSqlSession dbSqlSession = getDbSqlSession(); - try { - Connection connection = dbSqlSession.getSqlSession().getConnection(); + try (Connection connection = dbSqlSession.getSqlSession().getConnection();) { Exception exception = null; byte[] bytes = IoUtil.readInputStream(inputStream, resourceName); String ddlStatements = new String(bytes, StandardCharsets.UTF_8); @@ -318,12 +317,10 @@ protected void executeSchemaResource(String operation, String component, String sqlStatement = addSqlStatementPiece(sqlStatement, line.substring(0, line.length() - 1)); } - Statement jdbcStatement = connection.createStatement(); - try { + try (Statement jdbcStatement = connection.createStatement();) { logger.debug("SQL: {}", sqlStatement); jdbcStatement.execute(sqlStatement); - jdbcStatement.close(); } catch (Exception e) { if (exception == null) {