最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android數(shù)據(jù)庫(kù)操作工具類(lèi)分享

 更新時(shí)間:2017年10月09日 15:12:50   作者:JustingWang_1  
這篇文章主要為大家詳細(xì)介紹了Android數(shù)據(jù)庫(kù)操作工具類(lèi)的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android數(shù)據(jù)庫(kù)操作工具類(lèi)的具體代碼,供大家參考,具體內(nèi)容如下

HistoryDAO

public class HistoryDAO {
  private DBConnection dbc = null;
  private SQLiteDatabase db = null;
  private Context context;

  //數(shù)據(jù)庫(kù)上下文
  public HistoryDAO(Context context) {
    this.context = context;
  }
  //打開(kāi)數(shù)據(jù)庫(kù)
  public HistoryDAO open() {
    dbc = new DBConnection(context);
    db = dbc.getWritableDatabase();
    return this;
  }

  //關(guān)閉數(shù)據(jù)庫(kù)
  public void closeAll() {
    db.close();
    dbc.close();
  }

//  // 增加
//  public void add(Search_HistoryData data, String type) {
//    open();
//    ContentValues values = new ContentValues();
//    values.put("content", data.getContent());
//    values.put("type", data.getType());
//    db.insert("history", null, values);
//    closeAll();
//  }

  // 增加
  public void add(Search_HistoryData data, String tableName) {
    open();
    ContentValues values = new ContentValues();
    values.put("content", data.getContent());
    db.insert(tableName, null, values);
    closeAll();
  }

  // 增加 工具類(lèi)的最后五個(gè)專(zhuān)用
  public void addLawTool(Search_HistoryData data, String tableName) {
    open();
    ContentValues values = new ContentValues();
    values.put("content", data.getContent());
    values.put("_id", data.getId());
    db.insert(tableName, null, values);
    closeAll();
  }

  // 全查詢(xún)
  public List getAll(String TableName) {
    open();
    List ar = new ArrayList();
    Cursor c = db.rawQuery("select * from " + TableName, null);
    while (c.moveToNext()) {
      Map map = new HashMap();
      map.put("_id", c.getInt(c.getColumnIndex("_id")));
      map.put("content", c.getString(c.getColumnIndex("content")));
      ar.add(map);
    }
    closeAll();
    return ar;
  }

  // 刪除 根據(jù)id刪除
  public void delete(String tableName, int uid) {
    open();
    db.delete("history", "uid=" + uid, null);
    closeAll();
  }

  //清空表中所有數(shù)據(jù)
  public void delete(String tableName) {
    open();
    db.delete(tableName, null, null);
    closeAll();
  }

  //判斷是否存在
  public boolean searchResult(String tableName, String key) {
    open();
    Boolean booleans =
        db.rawQuery("select * from " + tableName + " where content = ?", new String[]{key}).moveToNext();
    closeAll();
    return booleans;
  }

  //根據(jù)庫(kù)查詢(xún)表字段
  public boolean searchResultToType(String content, String type) {
    open();
    Boolean booleans =
        db.rawQuery("select * from history where content = ? and type = ?", new String[]{content, type}).moveToNext();
    closeAll();
    return booleans;
  }

}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

朝阳区| 绥化市| 新乡市| 嵩明县| 樟树市| 璧山县| 县级市| 株洲县| 呼伦贝尔市| 阳信县| 包头市| 突泉县| 武宣县| 承德县| 逊克县| 高青县| 芦溪县| 临安市| 仙游县| 芜湖县| 肃宁县| 礼泉县| 桂平市| 东辽县| 丰台区| 绥化市| 桐庐县| 通渭县| 托里县| 天祝| 临汾市| 额济纳旗| 东至县| 西盟| 西安市| 和林格尔县| 千阳县| 青州市| 健康| 虹口区| 佳木斯市|