在Android中更新sqlite数据库时出现语法错误

时间:2017-04-26 09:02:04

标签: android database sqlite android-sqlite

更新数据时出错。错误是:

  

android.database.sqlite.SQLiteException:near" parth":语法错误   (代码1):,编译时:UPDATE收入SET income_balance =?哪里   income_name =?PARTH

public void update2( String name, String bal){
    SQLiteDatabase db = getWritableDatabase();
    ContentValues values = new ContentValues();
    //values.put(INCOME_NAME, name);
    values.put(INCOME_BALANCE, bal);
    db.update(TABLE_INCOME, values, INCOME_NAME+"=?"+name, new String[]{String.valueOf(name)});

1 个答案:

答案 0 :(得分:0)

INCOME_NAME+"=?"+name替换为INCOME_NAME+"=?"(不使用+name,您将此值设置为new String[]{String.valueOf(name)}行)

db.update(TABLE_INCOME, values, INCOME_NAME+"=?", new String[]{String.valueOf(name)});

或最终

db.update(TABLE_INCOME, values, INCOME_NAME+"='"+name+"'", null);