We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8fda43f commit 914130fCopy full SHA for 914130f
1 file changed
src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java
@@ -425,6 +425,16 @@ protected void initializeConnection(final Connection conn) throws SQLException {
425
for (final String sql : sqls) {
426
statement.execute(Objects.requireNonNull(sql, "null connectionInitSqls element"));
427
}
428
+ } catch (SQLException sqle) {
429
+ /*
430
+ * Need to close the connection here as the reference to it will be lost once the SQLEXception is
431
+ * thrown.
432
+ *
433
+ * Cast to AutoCloseable to avoid calling the deprecated method. The cast can be removed once the
434
+ * deprecated method has been removed.s
435
+ */
436
+ Utils.closeQuietly((AutoCloseable) conn);
437
+ throw sqle;
438
439
440
0 commit comments