Skip to content Skip to sidebar Skip to footer

Correct Way To Open/close The Database?

Right now I am using a static instance of the SQLOpenHelper class like so: public class DatabaseHelper extends SQLiteOpenHelper { private static DatabaseHelper mInstance = null

Solution 1:

The best way would be to put your query/transaction statements in try-catch and then release all your resources and close the connection in finally block.

try{
      mSomeList = mDatabaseProcessor.doSomeQueryAndReturnResults();
} catch(Exception exc){
    //Catch exceptions here
} 
finally{
    if(mDatabaseProcessor != null)
         mDatabaseProcessor.close();
}

Post a Comment for "Correct Way To Open/close The Database?"