It is really important to close resouces that aren't needed anymore - for example JDBC ResultSet's, Statement's and Connection's. It not only frees memory
available for your code but only give ability to make new recource connections :) (For example, MS SQL and other DBMS has limit on connection qunatity - if
your reach this limit you wan't be able to make new connections till old aren't closed). Here is simple example how to properly close JDBC resources after last usage:
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
... DB access code
} catch (Exception e){
... logging, something else
} finally {
//close ResultSet object
try {
if (rs != null) {
rs.close();
}
} catch (Exception e) {
Log.error(e);
}
//close Statement object
try {
if (pstmt != null) {
pstmt.close();
}
} catch (Exception e) {
Log.error(e);
}
//close Connection object
try {
if (con != null) {
con.close();
}
} catch (Exception e) {
Log.error(e);
}
}