SQLite Android 更新特定行
SQLite Android update a specific row
我在尝试更新 SQlite 中的行时遇到问题。
我想用名字 1 的任何人更新行 "name",并将其重命名为 bob。
我还想用任何 5 岁的人更新行 "age"。
ContentValues cv = new ContentValues();
cv.put("age", "bob");
cv.put("name", "2");
database.update("tblTest1", cv, "name", null);
cursor = database.rawQuery("select age,name from tblTest1", null);
displayAllInCursor(cursor);
当我 运行 这个程序的其余部分工作正常。在 logcat 中显示以下消息:
I/Choreographer﹕跳过39帧!应用程序可能在其主线程上做了太多工作。
我也不确定如何使用 ContentValues 创建删除。
任何帮助都会很棒。
先谢谢了。
这样做:
String[] args = new String[]{yourVariableName}; //this is for the condition
database.execSQL("UPDATE " + TABLENAME + " SET colum1Name='" + variable1 + "', column2Name='"+variable2+"' WHERE id=?", args);//replace id for your condition
Toast.makeText(getBaseContext(), "database updated!", Toast.LENGTH_LONG).show();
您只需更新 where 子句。
String where = "name ='name1'OR age = 5" ;
ContentValues cv = new ContentValues();
cv.put("age", "bob");
cv.put("name", "2");
database.update("tblTest1", cv, where, null);
cursor = database.rawQuery("select age,name from tblTest1", null);
displayAllInCursor(cursor);
我在尝试更新 SQlite 中的行时遇到问题。
我想用名字 1 的任何人更新行 "name",并将其重命名为 bob。 我还想用任何 5 岁的人更新行 "age"。
ContentValues cv = new ContentValues();
cv.put("age", "bob");
cv.put("name", "2");
database.update("tblTest1", cv, "name", null);
cursor = database.rawQuery("select age,name from tblTest1", null);
displayAllInCursor(cursor);
当我 运行 这个程序的其余部分工作正常。在 logcat 中显示以下消息:
I/Choreographer﹕跳过39帧!应用程序可能在其主线程上做了太多工作。
我也不确定如何使用 ContentValues 创建删除。 任何帮助都会很棒。 先谢谢了。
这样做:
String[] args = new String[]{yourVariableName}; //this is for the condition
database.execSQL("UPDATE " + TABLENAME + " SET colum1Name='" + variable1 + "', column2Name='"+variable2+"' WHERE id=?", args);//replace id for your condition
Toast.makeText(getBaseContext(), "database updated!", Toast.LENGTH_LONG).show();
您只需更新 where 子句。
String where = "name ='name1'OR age = 5" ;
ContentValues cv = new ContentValues();
cv.put("age", "bob");
cv.put("name", "2");
database.update("tblTest1", cv, where, null);
cursor = database.rawQuery("select age,name from tblTest1", null);
displayAllInCursor(cursor);