使用多个列值更新SQLITE

时间:2015-08-22 06:09:35

标签: android sqlite sql-update

for(int i = 0; i< subjectsforGrades.size(); i ++){

                        sql2 = "UPDATE " + DatabaseHelper.TABLE_4_NAME
                                + " SET "
                                + DatabaseHelper.TABLE_4_COL_3 + " = " + selectedGrades.get(i)
                                + " , "
                                + DatabaseHelper.TABLE_4_COL_4  + " = " + gpaforSubjects.get(i)
                                + " WHERE "
                                + DatabaseHelper.TABLE_4_COL_2 + " = " + subjectsforGrades.get(i);

                        dbHelper.executeQuery(sql2);
                    }

public void executeQuery(String sql){

    SQLiteDatabase db = this.getWritableDatabase();
    db.execSQL(sql);
}

subjectforGrades,selectedGrades,gpaforSubjects是arraylists

08-22 11:37:33.157 23019-23019 / com.example.sasankapabasara.pdmaplication E / SQLiteLog:(1)near“,”:语法错误

08-22 11:37:33.157  23019-23019/com.example.sasankapabasara.pdmaplication D/AndroidRuntime﹕ Shutting down VM

08-22 11:37:33.157  23019-23019/com.example.sasankapabasara.pdmaplication W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41ff6930)

08-22 11:37:33.177  23019-23019/com.example.sasankapabasara.pdmaplication E/AndroidRuntime﹕ FATAL EXCEPTION: main



    android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling: UPDATE gpa SET grade = A+ , gpa = 4.0 WHERE subid = 1

2 个答案:

答案 0 :(得分:0)

self.newArray = [[NSMutableArray alloc] init];

答案 1 :(得分:-1)

您的查询应该是这样的(使用" AND'而不是",")

sql2 = "UPDATE " + DatabaseHelper.TABLE_4_NAME + " SET " + DatabaseHelper.TABLE_4_COL_3 + " = '" + selectedGrades.get(i) + "' AND " +DatabaseHelper.TABLE_4_COL_4 + " = '" + gpaforSubjects.get(i) + "' WHERE " + DatabaseHelper.TABLE_4_COL_2 + " = '" + subjectsforGrades.get(i)+"'";