From 715e95ed80560f68cd493e36d9c3613696613371 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 | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 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..343fb08060 100644 --- a/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java +++ b/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java @@ -88,9 +88,9 @@ protected abstract void doExport(OutputStream outputStream, Print print) @Override public final Processor.ExecutionContext print( - final String jobId, final PJsonObject requestData, final Configuration config, - final File configDir, final File taskDirectory, final OutputStream outputStream) - throws Exception { + final String jobId, final PJsonObject requestData, final Configuration config, + final File configDir, final File taskDirectory, final OutputStream outputStream) + throws Exception { final Print print = getJasperPrint(jobId, requestData, config, configDir, taskDirectory); if (Thread.currentThread().isInterrupted()) { @@ -181,18 +181,24 @@ 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()); - } + } else { + connection = DriverManager.getConnection(template.getJdbcUrl()); + } - print = fillManager.fill( + print = fillManager.fill( jasperTemplateBuild.getAbsolutePath(), values.asMap(), connection); + } finally { + if (connection != null && !connection.isClosed()) { + connection.close(); + } + } } else { JRDataSource dataSource;