Skip to content

Commit 51a0237

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

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-2009 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,15 +34,24 @@ abstract class AbstractEmbeddedDatabaseConfigurer implements EmbeddedDatabaseCon
3534

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

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

0 commit comments

Comments
 (0)