title: Retrieving single data from SQLite and display in TextView (Android Development)
body: <p><strong>Intent</strong>: Retrieving single data from SQLite table and display in TextView</p>
  
  <p><strong>Case:</strong> Fail to retrieve data, and unable to show in mainactivity.</p>
  
  <p><strong>Expected Result:</strong> TextView displaying the current total bank balance in main activity (e.g. Total bal: $7600) </p>
  
  <p><strong>Note</strong> Please show me the code of mainactiviy on retrieving display data as well. Thanks in advance (and sorry for my bad english).</p>
  
  <pre><code>package com.fa.money;
  import java.util.ArrayList;
  import java.util.HashMap;
  import android.util.Log;
  import android.content.ContentValues;
  import android.content.Context;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  
  public class DBController  extends SQLiteOpenHelper {
  private static final String LOGCAT = null;
  
  public DBController(Context applicationcontext) {
      super(applicationcontext, "androidsqlite.db", null, 1);
      Log.d(LOGCAT,"Created");
  }
  
  @Override
  public void onCreate(SQLiteDatabase database) {
      String query, query2;
  //  query = "CREATE TABLE tbBank ( bankID INTEGER PRIMARY KEY, bankname TEXT)";
      query = "CREATE TABLE tbBank ( bankID INTEGER PRIMARY KEY AUTOINCREMENT, bankname TEXT, baccID TEXT, baccBal TEXT, remarks TEXT)";
      query2 = "CREATE TABLE tbMain (mainID INTEGER PRIMARY KEY AUTOINCREMENT, bankbal TEXT, loanbal TEXT)";
      database.execSQL(query);
     database.execSQL(query2);
  
      Log.d(LOGCAT,"Bank Account Created");
  }
  @Override
  public void onUpgrade(SQLiteDatabase database, int version_old, int current_version) {
      String query,query2;
      query = "DROP TABLE IF EXISTS tbBank";
      query2 = "DROP TABLE IF EXISTS tbMain";
      database.execSQL(query);
      database.execSQL(query2);
      onCreate(database);
  }
  
  public void addBank(HashMap&lt;String, String&gt; queryValues) {
      SQLiteDatabase database = this.getWritableDatabase();
      ContentValues values = new ContentValues();
      values.put("bankname", queryValues.get("bankname"));
      values.put("baccID", queryValues.get("bankaccid"));
      values.put("baccBal", queryValues.get("totalbal"));
      values.put("remarks", queryValues.get("remarks"));
      database.insert("tbBank", null, values);
      database.close();
  }
  
  public int updateBank(HashMap&lt;String, String&gt; queryValues) {
      SQLiteDatabase database = this.getWritableDatabase();    
      ContentValues values = new ContentValues();
      values.put("bankname", queryValues.get("bankname"));
      return database.update("tbBank", values, "bankID" + " = ?", new String[] { queryValues.get("bankID") });
      //String updateQuery = "Update  words set txtWord='"+word+"' where txtWord='"+ oldWord +"'";
      //Log.d(LOGCAT,updateQuery);
      //database.rawQuery(updateQuery, null);
      //return database.update("words", values, "txtWord  = ?", new String[] { word });
  }
  
  public void deleteBank(String id) {
      Log.d(LOGCAT,"delete");
      SQLiteDatabase database = this.getWritableDatabase();    
      String deleteQuery = "DELETE FROM  tbBank where bankID='"+ id +"'";
      Log.d("query",deleteQuery);     
      database.execSQL(deleteQuery);
  }
  
  public ArrayList&lt;HashMap&lt;String, String&gt;&gt; getAllbank() {
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; wordList;
      wordList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
      String selectQuery = "SELECT * FROM tbBank";
      SQLiteDatabase database = this.getWritableDatabase();
      Cursor cursor = database.rawQuery(selectQuery, null);
      if (cursor.moveToFirst()) {
          do {
              HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
              map.put("bankID", cursor.getString(0));
              map.put("bankname", cursor.getString(1));
              wordList.add(map);
          } while (cursor.moveToNext());
      }
  
  
      return wordList;
  }
  
  public HashMap&lt;String, String&gt; getBankinfo(String id) {
      HashMap&lt;String, String&gt; wordList = new HashMap&lt;String, String&gt;();
      SQLiteDatabase database = this.getReadableDatabase();
      String selectQuery = "SELECT * FROM tbBank where bankID='"+id+"'";
      Cursor cursor = database.rawQuery(selectQuery, null);
      if (cursor.moveToFirst()) {
          do {
                  //HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
              wordList.put("bankname", cursor.getString(1));
                 //wordList.add(map);
          } while (cursor.moveToNext());
      }                   
  return wordList;
  }
  //getbankbal - ERROR here !
  public String getBankbal() {
        String bankbalresult;
        SQLiteDatabase database = this.getReadableDatabase();
        String selectQuery = "SELECT bankbal FROM tbMain";
        Cursor cursor = database.rawQuery(selectQuery, null);
        if (cursor.moveToFirst()) {
          do {
              bankbalresult.put("bankbal", cursor.getString(1));
          } while (cursor.moveToNext());
        }           
        return bankbalresult;
      } }
  </code></pre>