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) });

你可能感兴趣的:(android,sqlite)