JAVA 建立 + DAO包 + 實現 +《增刪改查》+ 方法呼叫
阿新 • • 發佈:2019-02-10
public class sqlopenhelper_ { private Myhelper myhelper; public sqlopenhelper_(Myhelper myhelper) { this.myhelper = myhelper; } //新增 public void Insertdata(String name1,String jsons1){ //得到可讀的資料庫 SQLiteDatabase database = myhelper.getWritableDatabase(); //先刪除 database.delete("yingying", "name=?", new String[]{name1}); //新增欄位 ContentValues values = new ContentValues(); values.put("name",name1); values.put("jsons",jsons1); long yingying = database.insert("yingying", null, values); } //查詢方法 public String Selectdata(String name1){ //設定變數 String data=""; //得到可讀的資料庫 SQLiteDatabase database1 = myhelper.getWritableDatabase(); //根據條件查詢資料庫 Cursor cursor = database1.query("yingying", null, "name=?", new String[]{name1}, null, null, null); while (cursor.moveToNext()){ data = cursor.getString(cursor.getColumnIndex("jsons")); } returndata; } }