title: Using multiple tables in SQLite database android
body: <p>I am making an information system in android that first login and afterwards it asks the user to show the list of the employees and add new employee. so the problem is how to use a different table to store the information of an employee and show it in the other activity in a list view. here is my code </p>
  
  <p>This is the adapter class of the database.</p>
  
  <p>public class LoginDataBaseAdapter {</p>
  
  <pre><code>static final String DATABASE_NAME = "login.db";
  static final int DATABASE_VERSION = 1;
  public static final int NAME_COLUMN = 1;
  
  static final String DATABASE_CREATE = "create table "+"LOGIN"+
          "( " +"ID"+" integer primary key autoincrement,"+ "USERNAME  text,PASSWORD text); ";
  public  SQLiteDatabase db;
  private final Context context;
  
  private DbHelper dbHelper;
  public  LoginDataBaseAdapter(Context _context) 
  {
      context = _context;
      dbHelper = new DbHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
  }
  public  LoginDataBaseAdapter open() throws SQLException 
  {
      db = dbHelper.getWritableDatabase();
      return this;
  }
  public void close() 
  {
      db.close();
  }
  public  SQLiteDatabase getDatabaseInstance()
  {
      return db;
  }
  
  public void insertEntry(String userName,String password)
  {
     ContentValues newValues = new ContentValues();
     newValues.put("USERNAME", userName);
      newValues.put("PASSWORD",password);
  
      db.insert("LOGIN", null, newValues);
  
  }
  public int deleteEntry(String UserName)
  {
  
      String where="USERNAME=?";
      int numberOFEntriesDeleted= db.delete("LOGIN", where, new String[]{UserName}) ;
      return numberOFEntriesDeleted;
  }   
  public String getSinlgeEntry(String userName)
  {
      Cursor cursor=db.query("LOGIN", null, " USERNAME=?", new String[]{userName}, null, null, null);
      if(cursor.getCount()&lt;1) // UserName Not Exist
      {
          cursor.close();
          return "NOT EXIST";
      }
      cursor.moveToFirst();
      String password= cursor.getString(cursor.getColumnIndex("PASSWORD"));
      cursor.close();
      return password;                
  }
  public void  updateEntry(String userName,String password)
  {
      ContentValues updatedValues = new ContentValues();
  
      updatedValues.put("USERNAME", userName);
      updatedValues.put("PASSWORD",password);
  
      String where="USERNAME = ?";
      db.update("LOGIN",updatedValues, where, new String[]{userName});               
  }       
  </code></pre>
  
  <p>}</p>
  
  <p>this is the helper class.</p>
  
  <p>public class DbHelper extends SQLiteOpenHelper {</p>
  
  <pre><code>public DbHelper(Context context, String name, CursorFactory factory,
          int version) {
      super(context, name, factory, version);
      // TODO Auto-generated constructor stub
  }
  
  @Override
  public void onCreate(SQLiteDatabase _db) {
      // TODO Auto-generated method stub
      _db.execSQL(LoginDataBaseAdapter.DATABASE_CREATE);
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase _db, int _oldVersion, int _newVersion) {
  
      // TODO Auto-generated method stub
      Log.w("TaskDBAdapter", "Upgrading from version " + _oldVersion + " to " + _newVersion + ", which will destroy all old data");
  
      _db.execSQL("DROP TABLE IF EXISTS " + "TEMPLATE");
      onCreate(_db);
  }
  </code></pre>
  
  <p>}</p>