国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android數據庫操作工具類分享

2019-12-12 01:56:29
字體:
來源:轉載
供稿:網友

本文實例為大家分享了Android數據庫操作工具類的具體代碼,供大家參考,具體內容如下

HistoryDAO

public class HistoryDAO {  private DBConnection dbc = null;  private SQLiteDatabase db = null;  private Context context;  //數據庫上下文  public HistoryDAO(Context context) {    this.context = context;  }  //打開數據庫  public HistoryDAO open() {    dbc = new DBConnection(context);    db = dbc.getWritableDatabase();    return this;  }  //關閉數據庫  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();  }  // 增加 工具類的最后五個專用  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();  }  // 全查詢  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;  }  // 刪除 根據id刪除  public void delete(String tableName, int uid) {    open();    db.delete("history", "uid=" + uid, null);    closeAll();  }  //清空表中所有數據  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;  }  //根據庫查詢表字段  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;  }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 房产| 龙海市| 肇东市| 柳河县| 顺平县| 永德县| 滦平县| 龙井市| 梨树县| 札达县| 诸暨市| 濮阳市| 九江县| 利川市| 安岳县| 康乐县| 凤庆县| 大石桥市| 台前县| 盘山县| 白朗县| 辽中县| 亚东县| 迁西县| 云梦县| 沙湾县| 绥中县| 唐山市| 瓦房店市| 稷山县| 乌苏市| 江口县| 阳东县| 太湖县| 营口市| 新竹市| 孙吴县| 南靖县| 九台市| 广河县| 武宣县|