title: Android/SQLite right way to open/close db?
body: <p>Im a bit new to OOP so i want to know if im doing things correctly. For communication with database i have created a class SQLiteHelper witch does all the usual stuff (onCreate, onUpdate) and also opens and closes connection.</p>
  
  <p>Here is the class, at the moment it has just on table but more will be added:</p>
  
  <pre><code>public class SQLiteHelper extends SQLiteOpenHelper{
      public static final String DATABASE_NAME = "notebook";
      public static final int DATABASE_VERSION = 2;
  
      public static final String TABLE_LIST = "list";
      public static final String TABLE_LIST_ID = "_id";
      public static final String TABLE_LIST_NAME = "name";
  
      public SQLiteDatabase db;
  
      public SQLiteHelper(Context context) {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
          // TODO Auto-generated constructor stub
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          // TODO Auto-generated method stub
          db.execSQL("create table " + TABLE_LIST + "(" + TABLE_LIST_ID
                  + " integer primary key autoincrement, " + TABLE_LIST_NAME
                  + " text not null);");
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          // TODO Auto-generated method stub
          db.execSQL("DROP TABLE IF EXISTS " + TABLE_LIST);
          onCreate(db);
      }
  
      public void open(){
          db = getWritableDatabase();
      }
  
      public void close(){
          db.close();
      }
  }
  </code></pre>
  
  <p>And next for each table i will create a new class witch extends previous class andd where i do all the operations relevant to that specific table.
  For example ListSQL:</p>
  
  <pre><code>public class ListSQL extends SQLiteHelper {
  
      public ListSQL(Context context) {
          super(context);
      }
  
      public void delete(int id) {
          open();
          db.delete(TABLE_LIST, TABLE_LIST_ID + " = " + id, null);
          close();
      }
  
  }
  </code></pre>
  
  <p>My question is that in OOP is this the correct way of doing things? Espesially the usage of open/close methods and db and TABLE variables in ListSQL seem kind of strange to me?</p>