我遇到查询以执行更新我有正确执行更新的代码我只是不确定如果有人可以提供帮助那么查询会是什么太棒了我也传递了3个变量和3个旧变量以及id。我知道我所做的查询只是一次尝试。
public void updateTable(String newDate, String newMethod, String newAmount, int id, String oldDate, String oldMethod, String oldAmount){
db = this.getWritableDatabase();
String query = "UPDATE " + TABLE_INCOME + " SET " + COL2 + " " + COL3 + " " + COL4 + " = '" + newDate + newMethod + newAmount + "' WHERE " + COL1 + " = '" + id + "'" +
" AND " + COL2 + " " + COL3 + " " + COL4 + " = '" + oldDate + oldMethod + oldAmount + "'";
db.execSQL(query);
}
答案 0 :(得分:0)
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("COL2", newDate);
values.put("COL3", newMethod );
values.put("COL4", newAmount );
long result = db.update("TABLE_INCOME", values, "COL1 = " + "'" + String.valueOf(id) +"'" , null);
Log.i(TAG, " update result : " + result);
不要使用太多参数。如果你的id很独特就足够了。我希望它有所帮助