Exemplo n.º 1
0
  /**
   * 描述:判断关键字是否存在于数据库中
   *
   * @param keyword
   * @return
   */
  public boolean isExist(String keyword) {
    boolean result = false;
    SQLiteDatabase db = dbHelper.getReadableDatabase();

    if (db.isOpen()) {
      Cursor cursor =
          db.rawQuery("select keyword from keywords where keyword=?", new String[] {keyword});
      if (cursor.moveToFirst()) {
        result = true;
      }
      cursor.close();
      db.close();
    }
    return result;
  }
Exemplo n.º 2
0
  /**
   * 描述:获取数据库中的所有数据
   *
   * @return
   */
  public List<String> getKeywords() {
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    List<String> keywords = new ArrayList<String>();

    if (db.isOpen()) {
      Cursor cursor = db.rawQuery("select keyword from keywords", null);

      while (cursor.moveToNext()) {
        String keyword = cursor.getString(cursor.getColumnIndex("keyword"));
        keywords.add(keyword);
      }
      cursor.close();
      db.close();
    }
    return keywords;
  }