From 2c3ab5af3e60c088a9a6138418cc47054a1c341b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Thu, 5 Oct 2023 11:39:18 +0200 Subject: [PATCH] Close the database connection --- .../AbstractJasperReportOutputFormat.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java b/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java index beb5778235..94d623c198 100644 --- a/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java +++ b/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java @@ -181,19 +181,21 @@ public final Print getJasperPrint( } if (template.getJdbcUrl() != null) { - Connection connection; - if (template.getJdbcUser() != null) { - connection = DriverManager.getConnection( + Connection connection = null; + try { + if (template.getJdbcUser() != null) { + connection = DriverManager.getConnection( template.getJdbcUrl(), template.getJdbcUser(), template.getJdbcPassword()); - } else { - connection = DriverManager.getConnection(template.getJdbcUrl()); - } - - print = fillManager.fill( - jasperTemplateBuild.getAbsolutePath(), - values.asMap(), - connection); + } else { + connection = DriverManager.getConnection(template.getJdbcUrl()); + } + print = fillManager.fill(jasperTemplateBuild.getAbsolutePath(), values.asMap(), connection); + } finally { + if (connection != null && !connection.isClosed()) { + connection.close(); + } + } } else { JRDataSource dataSource; if (template.getTableDataKey() != null) {