Skip to content

Commit

Permalink
Merge pull request #3080 from mapfish/backport/3072-to-3.28
Browse files Browse the repository at this point in the history
[Backport 3.28] Close the database connection
  • Loading branch information
sebr72 authored Oct 20, 2023
2 parents 2e59c24 + 715e95e commit b0b6585
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b0b6585

Please sign in to comment.