From ce55412b002fa8755d2a17c12fda13814113197e 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 | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 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 3ca6b507b1..d8d35324a3 100644 --- a/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java +++ b/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java @@ -184,18 +184,23 @@ 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( + } 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;