尝试更新表时SQLite异常 - 无法识别的标记

时间:2015-08-10 04:17:09

标签: android sqlite

我想在我的SQLiteHelper类中通过这个方法更新我的SQLite数据库,我收到了错误:

android.database.sqlite.SQLiteException: unrecognized token: "55c7e253afcf48" (code 1): , while compiling: UPDATE login SET user_group=? WHERE uid=55c7e253afcf48.85187730
            at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)

除了额外的“.85187730”之外,uid是正确的......我不确定这些数字是什么意思。 这是我的更新方法:

//updating sqlite database with the group name
    public void updateUserGroup(String groupName) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(KEY_GROUP, groupName);
        HashMap<String, String> user = getUserDetails();
        String userID = user.get("uid");

        System.out.println("User id is: " + userID);

        db.update(TABLE_LOGIN, values, SQLiteHandler.KEY_UID + "=" + "userID", null);




    }

    /**
     * Getting user data from database
     * */
    public HashMap<String, String> getUserDetails() {
        HashMap<String, String> user = new HashMap<String, String>();
        String selectQuery = "SELECT  * FROM " + TABLE_LOGIN;

        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);
        // Move to first row
        cursor.moveToFirst();
        if (cursor.getCount() > 0) {
            user.put("name", cursor.getString(1));
            user.put("email", cursor.getString(2));
            user.put("user_group", cursor.getString(3));
            user.put("uid", cursor.getString(4));
            user.put("created_at", cursor.getString(5));
        }
        cursor.close();
        //db.close();
        // return user
        Log.d(TAG, "Fetching user from Sqlite: " + user.toString());

        return user;
    }

感谢任何帮助。

1 个答案:

答案 0 :(得分:9)

uid周围的引号错过了。

您应该传递每个字符串,以避免错误。

UPDATE login SET user_group=? WHERE uid="55c7e253afcf48.85187730"

在您的情况下,查询将类似于

HashMap<String, String> user = getUserDetails();
String userID = user.get("uid");
db.update(TABLE_LOGIN, values, SQLiteHandler.KEY_UID + "=\"" + userID + "\"", null);