title: Can't read from local SQLite database in Android?
body: <p>Hi, I am having trouble reading from a embedded SQLite database in my project.</p>
  
  <p>I want to get the data from one activity to another and displaying it in TextView.</p>
  
  <p>Here is my database tools class:</p>
  
  <pre><code>public class myDBTools extends SQLiteOpenHelper {
  
  private static String DB_PATH = "/data/data/com.example.appscan5/databases/";
  
  private static String DB_NAME = "productlist";
  
  private static SQLiteDatabase myDatabase;
  
  public myDBTools(Context applicationContext) {
      super(applicationContext, DB_NAME, null, 1);
  
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
      myDatabase= SQLiteDatabase.openDatabase(DB_PATH + DB_NAME,null, SQLiteDatabase.CREATE_IF_NECESSARY);
  
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  
  }
  
  public static HashMap&lt;String, String&gt; getProductInfo(String id) {
  
      HashMap&lt;String, String&gt; productMap = new HashMap&lt;String, String&gt;();
  
      String selectQuery = "SELECT * FROM products WHERE _id='" + id + "'";
  
      Cursor cursor = myDatabase.rawQuery(selectQuery, null);
  
      // move to the first row of dataBase
      if (cursor.moveToFirst()) {
  
          do {
  
              productMap.put("NumberId", cursor.getString(0));
              productMap.put("BarcodeId", cursor.getString(1));
              productMap.put("ProductName", cursor.getString(2));
              productMap.put("Calories", cursor.getString(3));
              productMap.put("Protein", cursor.getString(4));
              productMap.put("Carbohydrates", cursor.getString(5));
              productMap.put("Fats", cursor.getString(6));
              productMap.put("Grams", cursor.getString(7));
  
          } while (cursor.moveToNext());
  
      }
      return productMap;
  }
  }
  </code></pre>
  
  <p>Here is how I use it in another activity:</p>
  
  <pre><code>myDBTools mydbTools = new myDBTools(this);
  HashMap&lt;String, String&gt; productMap = mydbTools.getProductInfo(id);
  </code></pre>