android.database.sqlite.SQLiteException:near“ON”:语法错误(代码1):,编译时:INSERT INTO

时间:2017-03-21 14:09:34

标签: android sqlite android-sqlite

如果有人能告诉我更新sqlite中表格的正确语法,将会很有帮助。 我想使用sqlite更新表格,但我收到以下错误:

  

android.database.sqlite.SQLiteException:接近“ON”:语法错误(代码1):,同时编译:INSERT INTO cost(service_type,cost)VALUES('1000','Oil and Filter Change')ON DUPLICATE KEY UPDATE service_type ='Oil and Filter Change',cost ='1000';

代码:

public void UpdatePrice(String ser_type, String cost)
{
    String query = "INSERT INTO " + TABLE_COST +
            " (" + COLUMN_SERVICE_TYPE + "," + COLUMN_COST +") VALUES('"+
            cost + "','" +ser_type +"') ON DUPLICATE KEY UPDATE "+
            COLUMN_SERVICE_TYPE + "='" + ser_type + "',"+
            COLUMN_COST + "='" + cost + "';";

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(query, null);
    // Move to first row
    cursor.moveToFirst();

    cursor.close();
    db.close();
}

1 个答案:

答案 0 :(得分:0)

ON DUPLICATE KEY UPDATE目前还不是SQLite的有效语法。但是既然你感兴趣,你可以用here中描述的不同sytax达到同样的效果。