SQLite exception-unrecognized token when trying to update table

I am trying to update a SQLite database using this method in my SQLiteHelper class and I am getting the error:

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)

      

The uid is correct except for the extra ".85187730" at the end ... I'm not sure what these numbers mean. Here is my update method:

//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;
    }

      

Any help is appreciated.

+3


source to share


1 answer


You missed quotes around yours uid

.

You must pass each line as shown below to avoid errors.

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

      



and in your case the request will look like

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

      

+9


source







All Articles