Should a database connection stay open all the time or only be opened when needed?
The database connection must be opened only when its needed and closed after doing all the necessary job with it. Code sample: Prior to Java 7: Connection con = null; try { con = … //retrieve the database connection //do your work… } catch (SQLException e) { //handle the exception } finally { try { … Read more