package com.bwei.db; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; /** * Created by 杨柳 on 2018/7/29. */ public class UserDao { private final UserHelper userHelper; private final SQLiteDatabase writableDatabase; private Context context; public UserDao(Context context) { userHelper = new UserHelper(context); writableDatabase = userHelper.getWritableDatabase(); } public void replace(UserBean userBean){ ContentValues value = new ContentValues(); value.put("url",userBean.getUrl()); value.put("NeiRou",userBean.getNeiRou()); writableDatabase.replace("user",null,value); } public UserBean query(String url){ Cursor cursor = writableDatabase.rawQuery("select * from user where url = ?", new String[]{url}); UserBean userBean = null; if (cursor.moveToNext()){ //cursor.getString(cursor.getColumnIndex("url")); //cursor.getString(cursor.getColumnIndex("NeiRou")); userBean = new UserBean( cursor.getString(cursor.getColumnIndex("url")), cursor.getString(cursor.getColumnIndex("NeiRou"))); } return userBean; } }
MyDao
最新推荐文章于 2020-11-23 03:46:43 发布