If you are doing any database operation in your program, then finally block
is good choice.
So,Using finally block here, It closes database automatically.
For example:
try
{
//code of operation
}
catch(Exception error)
{ //code to handle exception
error.printStackTrace();
}
finally
{ //any code which need to execute mandatory
commit();
db.close();
}
In the above example, try block
handles the opening DB connection and inserting,retrieving or updating the DB. catch block
handles exception and finally block
close all DB connection.