title: How can I change between two tables in SQL database when a button is clicked?
body: <p>I have a dictionary app getting data from SQL database.
  This database has a "First table" table with 3 columns id, word, meaning ( word in french meaning in English)</p>
  
  <p>I've insert a new table "Second table" with the same columns but this time is the opposite I mean (word in English meaning in french)
  I want to insert a button to switch between search method "search using french Word and button to search using English word"
  when user clicked the button "FR > ENG" I want to get the data from the first table (word in french meaning in English) and do the opposite when click 
  button "ENG > FR" using the second table that I've added before (word in English meaning in french)</p>
  
  <p>DataBaseHelper.java</p>
  
  <pre><code>public class DataBaseHelper extends SQLiteOpenHelper {
      public static String DB_PATH;
      public final Context context;
      public SQLiteDatabase database;
      public static String DB_NAME = "Database";
      public SQLiteDatabase getDb() {
          return this.database;
      }
  
  
      public DataBaseHelper(Context context) {
          super(context, DB_NAME, null, 1);
  
          this.context = context;
          DB_PATH = String.format("//data//data//%s//databases//", new Object[]{context.getPackageName()});
          openDataBase();
      }
      public void createDataBase() {
          if (checkDataBase()) {
              Log.i(getClass().toString(), "Database already exists");
              return;
          }
          getReadableDatabase();
          try {
              copyDataBase();
          } catch (IOException e) {
              Log.e(getClass().toString(), "Copying error");
              throw new Error("Error copying database!");
          }
      }
  
      private boolean checkDataBase() {
          SQLiteDatabase checkDb = null;
          try {
              checkDb = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null, 0);
          } catch (SQLException e) {
              Log.e(getClass().toString(), "Error while checking db");
          }
          if (checkDb != null) {
              checkDb.close();
          }
          if (checkDb != null) {
              return true;
          }
          return false;
      }
  
      private void copyDataBase() throws IOException {
          InputStream externalDbStream = this.context.getAssets().open(DB_NAME);
          OutputStream localDbStream = new FileOutputStream(DB_PATH + DB_NAME);
          byte[] buffer = new byte[1024];
          while (true) {
              int bytesRead = externalDbStream.read(buffer);
              if (bytesRead &gt; 0) {
                  localDbStream.write(buffer, 0, bytesRead);
              } else {
                  localDbStream.close();
                  externalDbStream.close();
                  return;
              }
          }
      }
  
      public SQLiteDatabase openDataBase() throws SQLException {
          String path = DB_PATH + DB_NAME;
          if (this.database == null) {
              createDataBase();
              this.database = SQLiteDatabase.openDatabase(path, null, 0);
          }
          return this.database;
      }
  
      public synchronized void close() {
          if (this.database != null) {
              this.database.close();
          }
          super.close();
      }
  
      public void onCreate(SQLiteDatabase db) {
      }
  
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      }
  }
  </code></pre>
  
  <p>DataManager.java</p>
  
  <pre><code>import android.content.Context;
  import android.database.Cursor;
  import android.database.SQLException;
  import android.database.sqlite.SQLiteDatabase;
  import android.util.Base64;
  
  import java.io.UnsupportedEncodingException;
  import java.util.ArrayList;
  import java.util.List;
  
  public class DataManager {
      DataBaseHelper myDbHelper;
      SQLiteDatabase db;
  
      public DataManager(Context context) {
          myDbHelper = new DataBaseHelper(context);
          myDbHelper.createDataBase();
          try {
              myDbHelper.openDataBase();
          } catch (SQLException sqle) {
              sqle.printStackTrace();
          }
          db = myDbHelper.getReadableDatabase();
      }
  
      //Get All Data
      public List&lt;Word&gt; getAllData() {
          Cursor cur = db.rawQuery("select * from table_fr_eng LIMIT 5000;", null);
          List&lt;Word&gt; item_data = new ArrayList&lt;Word&gt;();
          if (cur.getCount() != 1) {
              if (cur.moveToFirst()) {
                  do {
                      Word obj = new Word();
                      obj.id = cur.getString(cur.getColumnIndex("Id"));
                      obj.word = cur.getString(cur.getColumnIndex("Word"));
                      obj.is_fav = cur.getString(cur.getColumnIndex("is_favourite"));
                      if (obj.is_fav!=null) {
                      } else {
                          obj.is_fav="0";
                      }
                      obj.meaning = cur.getString(cur.getColumnIndex("Meaning"));
                      item_data.add(obj);
                  } while (cur.moveToNext());
              }
          }
          return item_data;
      }
  
      //Get Search Data
      public List&lt;Word&gt; getAllSearchData(String search) {
          Cursor cur = db.rawQuery("SELECT * FROM table_fr_eng WHERE Word LIKE '" + search + "%' LIMIT 30", null);
          List&lt;Word&gt; item_data = new ArrayList&lt;Word&gt;();
          if (cur.getCount() != 0) {
              if (cur.moveToFirst()) {
                  do {
                      Word obj = new Word();
                      obj.id = cur.getString(cur.getColumnIndex("Id"));
                      obj.word = cur.getString(cur.getColumnIndex("Word"));
                      obj.is_fav = cur.getString(cur.getColumnIndex("is_favourite"));
                      if (obj.is_fav!=null) {
                      } else {
                          obj.is_fav="0";
                      }
                      obj.meaning = cur.getString(cur.getColumnIndex("Meaning"));
                      item_data.add(obj);
                  } while (cur.moveToNext());
              }
          }
          return item_data;
      }
  
      //Add Word And Meaning 
      public Boolean InsertWord(String strWord, String strMeaning) {
          String insertQuery = "INSERT INTO table_fr_eng(Word,Meaning) values('" + strWord + "','"
                  + strMeaning + "')";
          db.execSQL(insertQuery);
          db.close();
          return true;
      }
  
      //Get Day of The Word
      public Word DayOfWord() {
          Cursor cur = db.rawQuery("SELECT * FROM table_fr_eng ORDER BY RANDOM() LIMIT 1 ;",null);
          Word objWord = new Word();
          if (cur.getCount() != 0) {
              if (cur.moveToFirst()) {
                  do {
                      objWord.word = cur.getString(cur.getColumnIndex("Word"));
                      objWord.meaning = cur.getString(cur.getColumnIndex("Meaning"));
                  } while (cur.moveToNext());
              }
          }
          return objWord;
      }
  
      //Add Favourite Word
      public void FavouriteWord(String id) {
          String updateQuery = "UPDATE table_fr_eng SET is_favourite='"+1+"' WHERE Id=" +id;
          SQLiteDatabase db = this.myDbHelper.getWritableDatabase();
          db.execSQL(updateQuery);
          db.close();
      }
      //Add UnFavourite Word
      public void UnFavouriteWord(String id) {
          String updateQuery = "UPDATE table_fr_eng SET is_favourite='' WHERE Id=" +id;
          SQLiteDatabase db = this.myDbHelper.getWritableDatabase();
          db.execSQL(updateQuery);
          db.close();
      }
      //Get All Favourite Word
      public List&lt;Word&gt; getAllFavouriteData() {
          Cursor cur = db.rawQuery("select * from table_fr_eng where is_favourite=1;",null);
          List&lt;Word&gt; item_data = new ArrayList&lt;Word&gt;();
          if (cur.getCount() != 0) {
              if (cur.moveToFirst()) {
                  do {
                      Word obj = new Word();
                      obj.id = cur.getString(cur.getColumnIndex("Id"));
                      obj.word = cur.getString(cur.getColumnIndex("Word"));
                      if (obj.is_fav!=null) {
                      } else {
                          obj.is_fav="1";
                      }
                      obj.meaning = cur.getString(cur.getColumnIndex("Meaning"));
                      item_data.add(obj);
                  } while (cur.moveToNext());
              }
          }
          return item_data;
      }
      //Add History 
      public void InsertHistoryWord(String word, String meaning) {
          String insertQuery = "INSERT INTO tblHistory(word,meaning) values('" + word + "','"
                  + Base64.encodeToString(meaning.getBytes(), Base64.DEFAULT) + "')";
          db.execSQL(insertQuery);
          db.close();
      }
  
      //Get All History Word
      public List&lt;Word&gt; getAllHistoryData() {
          Cursor cur = db.rawQuery("select * from tblHistory;", null);
          List&lt;Word&gt; item_data = new ArrayList&lt;Word&gt;();
          if (cur.getCount() != 0) {
              if (cur.moveToFirst()) {
                  do {
                      Word obj = new Word();
                      obj.id = cur.getString(cur.getColumnIndex("Id"));
                      obj.word = cur.getString(cur.getColumnIndex("word"));
                      obj.meaning = cur.getString(cur.getColumnIndex("meaning"));
                      byte[] data1 = Base64.decode(obj.meaning, Base64.DEFAULT);
                      try {
                          obj.meaning = new String(data1, "UTF-8");
                      } catch (UnsupportedEncodingException e) {
                          e.printStackTrace();
                      }
                      item_data.add(obj);
                  } while (cur.moveToNext());
              }
          }
          return item_data;
      }
  
      //Delete History 
      public List&lt;Word&gt; getDeleteHistoryData() {
          List&lt;Word&gt; item_data = new ArrayList&lt;Word&gt;();
          String deleteQuery = "delete from tblHistory";
          db.execSQL(deleteQuery);
          db.close();
          return item_data;
      }
  
      //Get Quiz Word and Meaning
      public List&lt;Word&gt; Quiz() {
          Cursor cur = db.rawQuery("SELECT * FROM table_fr_eng ORDER BY RANDOM() LIMIT 4 ;",null);
          List&lt;Word&gt; item_data = new ArrayList&lt;Word&gt;();
          if (cur.getCount() != 0) {
              if (cur.moveToFirst()) {
                  do {
                      Word obj = new Word();
                      obj.id = cur.getString(cur.getColumnIndex("Id"));
                      obj.word = cur.getString(cur.getColumnIndex("Word"));
                      obj.meaning = cur.getString(cur.getColumnIndex("Meaning"));
                      item_data.add(obj);
                  } while (cur.moveToNext());
              }
          }
          return item_data;
      }
  
      //Delete Favourite Word
      public List&lt;Word&gt; getDeleteFavouriteData() {
          List&lt;Word&gt; item_data = new ArrayList&lt;Word&gt;();
          String deleteQuery = "delete from table_fr_eng where is_favourite";
          db.execSQL(deleteQuery);
          db.close();
          return item_data;
      }
  
  }
  </code></pre>