From b0690c5ad3f136d7d439e6263e1c52131698c8da Mon Sep 17 00:00:00 2001 From: Jason Pickering Date: Mon, 13 Nov 2023 12:36:19 +0300 Subject: [PATCH] fix: Close database connection after test statement. (#15640) * fix: Close database connection after test statement. --- .../java/org/hisp/dhis/datasource/DatabasePoolUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/datasource/DatabasePoolUtils.java b/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/datasource/DatabasePoolUtils.java index 46f31e29e606..bff36ed88d83 100644 --- a/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/datasource/DatabasePoolUtils.java +++ b/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/datasource/DatabasePoolUtils.java @@ -216,10 +216,12 @@ public static DataSource createC3p0DbPool(PoolConfig config) } public static void testConnection(DataSource dataSource) throws SQLException { - Connection conn = dataSource.getConnection(); - try (Statement stmt = conn.createStatement()) { + try (Connection conn = dataSource.getConnection(); + Statement stmt = conn.createStatement()) { stmt.executeQuery("select 'connection_test' as connection_test;"); + } catch (SQLException e) { + log.error(e.getMessage()); } } }