Sqlite 之update

前端之家收集整理的这篇文章主要介绍了Sqlite 之update前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
update(String table,ContentValues values,String whereClause,String[] whereArgs)
Convenience method for updating rows in the database.//方便的方法更新数据库中的行
table 数据库的表名
values 用来更新数据的ContentValue 的对象
whereClause 用来指定更新的行,一般为 “_id = ?” ,若为null,所有的行均被更新
whereArgs where 语句中表达式的?占位参数列表,参数只能为String类型,当为1时,用new
String[]{Integer.toString(1)},表示_id = 1 的那行改变数据
一、
sqliteDatabase db = getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(IDCODE,id);
cv.put(NAME,name);
cv.put(SEX,sex);
int flag = db.update(T_NAME,cv,ID + " = ? ",
new String[] { Integer.toString(_id) }); //更新成功返回1,否则返回0;
二、
sql 语句:
db.execsql("update " + T_NAME
+ " set s_id=?,s_name=?,s_sex=? where _id=?",new Object[] {
id,name,sex,Integer.toString(_id) });
原文链接:https://www.f2er.com/sqlite/201893.html

猜你在找的Sqlite相关文章