Any DB connections that are opened must be explicitly closed. The logic to get the connection and query the DB using a prepared statement should be enclosed in a try catch block. The corresponding finally block should have the logic to close any prepared statements and DB connections.
// See the Sample Code template given below to understand how the code should be structured // Note : Only minimal code is shown here. The intent is to convey the structure //Pay attention to the code highlighted in Yellow
override function search(criteria : ISOLocationSearchCriteria) : List<T> {
var _dbConnection : Connection = null
.............some code….
.............some code….
try {
// Step 1. Get the connection
_dbConnection = DBConnectionHelper.getConnection(DB_GROUP)
// Step 2. EXECUTE THE Prepared statement AND ANY OTHER LOGIC
.................
} catch (ex : DBConnectionException) {
// Step 3 : Catch and Log any DB exceptions.
............
// Step 4 : Optionally rethrow the exception
throw ex
} catch (ex : Exception) {
// Step 5 : Catch and log any other custom exceptions
.............
// Step 6 : Optionally rethrow the exception
throw ex
} finally {
// Step 7 : Close any prepared statements and DB connections
// Close any prepared statements
_preparedStatement?.close()
// Close any DB connections
_dbConnection?.close()
_
}