Skip to content

Commit b0b6585

Browse files
authored
Merge pull request #3080 from mapfish/backport/3072-to-3.28
[Backport 3.28] Close the database connection
2 parents 2e59c24 + 715e95e commit b0b6585

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ protected abstract void doExport(OutputStream outputStream, Print print)
8888

8989
@Override
9090
public final Processor.ExecutionContext print(
91-
final String jobId, final PJsonObject requestData, final Configuration config,
92-
final File configDir, final File taskDirectory, final OutputStream outputStream)
93-
throws Exception {
91+
final String jobId, final PJsonObject requestData, final Configuration config,
92+
final File configDir, final File taskDirectory, final OutputStream outputStream)
93+
throws Exception {
9494
final Print print = getJasperPrint(jobId, requestData, config, configDir, taskDirectory);
9595

9696
if (Thread.currentThread().isInterrupted()) {
@@ -181,18 +181,24 @@ 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+
print = fillManager.fill(
193194
jasperTemplateBuild.getAbsolutePath(),
194195
values.asMap(),
195196
connection);
197+
} finally {
198+
if (connection != null && !connection.isClosed()) {
199+
connection.close();
200+
}
201+
}
196202

197203
} else {
198204
JRDataSource dataSource;

0 commit comments

Comments
 (0)