title: Fetching single value from SQLite in android
body: <p>I'm developing my firs app for android right now, I am using multiple tables to get and insert data. during the development and found myself fetching data from the table with has only two columns <code>STATS(_id, stat_name)</code>. What my problem is? I have an activity with 10 buttons, and every button correlates with one <code>stat_name</code>. When users presses one of the buttons application is "going" to <code>STATS</code> table to get correct <code>_id</code> and then is inputting this <code>_id</code> to another table <code>GAME_STATS(_id, PlayerId (fk), GameId(fk), StatsId(fk)(andmore))</code> on <code>STATS._id = GAME_STATS.StatsId</code> and I basicly have to do similar operation for <code>PlayerId</code>. </p>
  
  <p>Right now, I'm doing it this way:</p>
  
  <pre><code>public String getStatId(String statName){
      String statId = "Error";
      Cursor c = mDb.query(STAT_TABLE, new String[] {AbstractDbAdapter.STAT_ID, AbstractDbAdapter.STAT_NAME}, AbstractDbAdapter.STAT_NAME+ " = " +statName, null, null, null, null);
      int count = c.getCount();
      if(count == 1){
          c.moveToFirst();
          statId = c.getString(c.getColumnIndex(AbstractDbAdapter.STAT_ID));
      }
      c.close();
      mDb.close();
      Log.d("FootballApp","StatId =" +statId);
      return statId;      
  }
  </code></pre>
  
  <p>What my problem is, that I know that there SHOULD be only one value returned, and I still have to use Cursor, to do so. Also, in my opinion, it looks way to complicated and time consuming wo write all that code just to get one id from one table. I have 9 tables in my application, and I will have to write similar method every time I need _id from different table when I have, for example, only name. </p>
  
  <p>Can someone tell me if there is easier way to do all that? Please :)
  thanks! :)</p>