Skip to content

Commit

Permalink
Close the database connection
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner authored and sebr72 committed Oct 20, 2023
1 parent 2e59c24 commit 715e95e
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 715e95e

Please sign in to comment.