title: Is it OK to use static "database helper" class?
body: <p>I have some <strong>Android</strong> projects and most of them are connected with <strong>SQLite databases</strong>. I'm interested is it a good programming practice (or a bad habbit) to use some static class like "<strong>DatabaseHelper.class</strong>" in which I would have all static method related for database manipulation. For example</p>
  
  <pre><code>public static int getId(Context context, String name) {
      dbInit(context);
  
      Cursor result = db.rawQuery("SELECT some_id FROM table WHERE some_name = '" + name + "'", null);
      result.moveToFirst();
      int id = result.getInt(result.getColumnIndex("some_id"));
      result.close();
  
      return id;
  }
  </code></pre>
  
  <p>where <strong>dbInit(context)</strong> <em>(which is used in all my static methods for database manipluation)</em> is</p>
  
  <pre><code>private static void dbInit(Context context) {
      if (db == null) {
          db = context.openOrCreateDatabase(DATABASE_NAME, Context.MODE_PRIVATE, null);
      }
  }
  </code></pre>
  
  <p>Then when I need something I can easily call those method(s) with for example</p>
  
  <pre><code>int id = DatabaseHelper.getId(this, "Abc");
  </code></pre>
  
  <p><strong>EDIT:</strong> Do I have to use dbClose on every connection or leave it open per-activity and close per-activity? So do I have change that upper code to something like this?</p>
  
  <pre><code>    ...
      dbClose();
  
      return id;
  }
  
  private static void dbClose() {
      if (db != null) {
          db.close();
      }
  }
  </code></pre>