/**
*
查找一条数据
*
@param
uid
*/
public
user
find(integer
uid){
sqlitedatabase
db=dbopenhelper.getreadabledatabase()
//创建数据库辅助类
cursor
cursor
=db.rawquery("select
*
from
user
where
uid=?",
new
string[]{uid.tostring()})
//创建一个游标
if(cursor.movetofirst()){
//循环遍历查找数组
int
uid2=cursor.getint(cursor.getcolumnindex("uid"))
string
uname=cursor.getstring(cursor.getcolumnindex("uname"))
string
uaddress=cursor.getstring(cursor.getcolumnindex("uaddress"))
user
user=new
user()
user.setuid(uid2)
user.setuname(uname)
user.setuaddress(uaddress)
return
user
}
cursor.close()
return
null
}
SQLiteDatabase 给我提供的方法很不实用,还是建议楼主自己写sql语句,参数想怎么传都可以\x0d\x0a例如:Cursor c = db.rawQuery("select * from user where username=? and password = ?",\x0d\x0anew Stirng[]{"用户名","密码"})\x0d\x0a\x0d\x0a如果你非要调用SQLiteDatabase的query方法,那可以这样\x0d\x0adb.query("表名", new String[]{"字段1,字段2"}, "条件1=? and 条件2=?", new String[]{"条件1的值,条件2的值"},null,null,null)SQLiteDatabase db=dbHelper.getWritableDatabase()
db.delete("record","pulse=?and dia_pre=?",new String[]{record.get_pulse(),record.get_dia_pre()})//删除所有pulse等于给定值并且dia_pre等于给定值的记录
Cursor cursor=db.query("record",null,"sys_pre&gt?and dia_pre&lt?",new String[]{"120","85"},null,null,null)//多条件查询记得String是数组
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)