Skip to content

Commit 602bd1c

Browse files
authored
Merge pull request #3081 from mapfish/backport/3072-to-3.29
[Backport 3.29] Close the database connection
2 parents 57023fb + 6bbbdec commit 602bd1c

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

core/src/main/java/org/mapfish/print/output/AbstractJasperReportOutputFormat.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,22 @@ public final Print getJasperPrint(
181181

182182
}
183183
if (template.getJdbcUrl() != null) {
184-
Connection connection;
185-
if (template.getJdbcUser() != null) {
186-
connection = DriverManager.getConnection(
184+
Connection connection = null;
185+
try {
186+
if (template.getJdbcUser() != null) {
187+
connection = DriverManager.getConnection(
187188
template.getJdbcUrl(), template.getJdbcUser(), template.getJdbcPassword());
188-
} else {
189-
connection = DriverManager.getConnection(template.getJdbcUrl());
190-
}
189+
} else {
190+
connection = DriverManager.getConnection(template.getJdbcUrl());
191+
}
191192

192-
print = fillManager.fill(
193-
jasperTemplateBuild.getAbsolutePath(),
194-
values.asMap(),
195-
connection);
193+
print = fillManager.fill(jasperTemplateBuild.getAbsolutePath(), values.asMap(), connection);
196194

195+
} finally {
196+
if (connection != null && !connection.isClosed()) {
197+
connection.close();
198+
}
199+
}
197200
} else {
198201
JRDataSource dataSource;
199202
if (template.getTableDataKey() != null) {

0 commit comments

Comments
 (0)