package com.example.ggq.gaoguoqing2018072403.db; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; public class ShopDao { private final SQLiteDatabase db; public ShopDao(Context context) { ShopOpenHelper helper = new ShopOpenHelper(context); db = helper.getWritableDatabase(); } public void insert(ShopBean bean){ ContentValues values = new ContentValues(); values.put("url",bean.url); values.put("json",bean.json); db.replace("shop",null,values); } public ShopBean query(String url){ ShopBean bean = null; Cursor cursor = db.rawQuery("select * from shop where url = ?", new String[]{url}); while (cursor.moveToNext()){ bean = new ShopBean(); bean._id = cursor.getInt(cursor.getColumnIndex("_id")); bean.url = cursor.getString(cursor.getColumnIndex("url")); bean.json = cursor.getString(cursor.getColumnIndex("json")); } return bean; } }
Dao
最新推荐文章于 2021-10-28 17:32:19 发布