Skip to content

Commit aa0f117

Browse files
committed
AbstractEmbeddedDatabaseConfigurer explicitly closes JDBC Connection on shutdown
Issue: SPR-13474 (cherry picked from commit b23c232)
1 parent 7202793 commit aa0f117

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/AbstractEmbeddedDatabaseConfigurer.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
1818

1919
import java.sql.Connection;
2020
import java.sql.SQLException;
21-
import java.sql.Statement;
2221
import javax.sql.DataSource;
2322

2423
import org.apache.commons.logging.Log;
@@ -35,16 +34,25 @@ abstract class AbstractEmbeddedDatabaseConfigurer implements EmbeddedDatabaseCon
3534

3635
protected final Log logger = LogFactory.getLog(getClass());
3736

37+
3838
@Override
3939
public void shutdown(DataSource dataSource, String databaseName) {
40+
Connection con = null;
4041
try {
41-
Connection connection = dataSource.getConnection();
42-
Statement stmt = connection.createStatement();
43-
stmt.execute("SHUTDOWN");
42+
con = dataSource.getConnection();
43+
con.createStatement().execute("SHUTDOWN");
4444
}
4545
catch (SQLException ex) {
46-
if (logger.isWarnEnabled()) {
47-
logger.warn("Could not shutdown embedded database", ex);
46+
logger.warn("Could not shut down embedded database", ex);
47+
}
48+
finally {
49+
if (con != null) {
50+
try {
51+
con.close();
52+
}
53+
catch (Throwable ex) {
54+
logger.debug("Could not close JDBC Connection on shutdown", ex);
55+
}
4856
}
4957
}
5058
}

0 commit comments

Comments
 (0)