how to add WHERE clause to Query on android

后端 未结 3 1038
清酒与你
清酒与你 2021-02-19 19:13

I would like to limit the results to those whose KEY_HOMEID is equal to journalId. I\'ve been on this for a couple days any help would be appreciated.

public Curso

3条回答
  •  误落风尘
    2021-02-19 19:48

    It makes your code more clear if you'll use it where arguments (in query parameters) Example:

            String [] settingsProjection = {
                    DBContract.Settings._ID,
                    DBContract.Settings.COLUMN_NAME_USER_ID,
                    DBContract.Settings.COLUMN_NAME_AUTO_LOGIN
            };
    
            String whereClause = DBContract.Settings.COLUMN_NAME_USER_ID+"=?";
            String [] whereArgs = {userId.toString()};
    
            Cursor c = db.query(
                    DBContract.Settings.TABLE_NAME,
                    settingsProjection,
                    whereClause,
                    whereArgs,
                    null,
                    null,
                    null
            );
    

提交回复
热议问题