Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 3.28] Close the database connection #3080

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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