cant use like clause in android app

后端 未结 7 783
萌比男神i
萌比男神i 2020-12-07 01:23

I am working on a database with sqllite in an android app I want to retrieve sm data using a like clause ex:

Cursor c = myDB.query(MY_DATABASE_TABLE, null,          


        
7条回答
  •  清歌不尽
    2020-12-07 01:48

    If you wish to use query() instead of rawQuery(), you can do it like so:

    // searchString is the string to search for
    final String whereClause = "MyColumnName" + " like ?";
    String[] whereArgs = new String[]{"%" + searchString + "%"};
    
    Cursor cursor = sqLiteDatabase.query("MyTableName",
            null, // columns
            whereClause, // selection
            whereArgs, // selectionArgs
            null, // groupBy
            null, // having
            null, // orderBy
            null); // limit
    

提交回复
热议问题