Skip to content

Commit

Permalink
Make sure that we auto close the JDBC Connection and Statement when e…
Browse files Browse the repository at this point in the history
…xecuting a schema resource
  • Loading branch information
filiphr committed Aug 20, 2024
1 parent eab1f9c commit 346b85d
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 346b85d

Please sign in to comment.