Closing resultSet does not close the database connection. You need to do this separately.
Usually you want to close the resource as follows:
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
log.info("closing resultset caused exception", e);
}
}
, DatabaseUtil, .
try-with-resources , , . resultSet ( , ), , . , try-with-resources, , close. , resultSet , ( , ), - , , .
. , finally, , , ( , ).
, (, OP , , , , , ), , :
Class Class1<T>
{
public T getColumn(DataSource ds)
{
T value = null;
Connection con = null;
Statement st = null;
try
{
con = ds.getConnection();
st = con.createStatement();
ResultSet rs = st.executeQuery("select 1 from dual");
rs.next();
Object o = rs.getObject(1);
value = (T) o;
}
finally
{
if (st != null) { st.close(); }
if (con != null) { con.close(); }
}
return i;
}
}
statement.close SQLException, finally , , . , , , ( ). . " ! , , .
, - , mapset , . spring -jdbc, .