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 5df670ae7b..af82451ba7 100644 --- a/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java +++ b/core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java @@ -194,17 +194,22 @@ public final Print getJasperPrint( } } if (template.getJdbcUrl() != null) { - Connection connection; - 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); + 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); + } finally { + if (connection != null && !connection.isClosed()) { + connection.close(); + } + } } else { JRDataSource dataSource; if (template.getTableDataKey() != null) {