Android sqlite: how to retrieve specific data from particular column?

后端 未结 9 2081
生来不讨喜
生来不讨喜 2020-12-31 18:17

I am developing restaurant menu application. My app has a sqlite table which has these columns:

\"id\", \"category\", \"item_name\"

Content

相关标签:
9条回答
  • 2020-12-31 18:34

    Try this:

    String vg ="Veg";
    return database.rawQuery("SELECT * FROM subjects where " + KEY_CATEGORY + " = ?",
                                new String[]{vg});
    
    0 讨论(0)
  • 2020-12-31 18:38
      String q="SELECT * FROM todo WHERE category='" + vg +"'";
        SQLiteDatabase db = this.getWritableDatabase();
            Cursor cursor = null;
            cursor = db.rawQuery(q, null);
            if (cursor.moveToFirst()) {
                do {
    
                } while (cursor.moveToNext());
    
            }
    
    0 讨论(0)
  • 2020-12-31 18:44

    try this:

    String query = "SELECT * FROM todo WHERE category='" + vg;
    
    Cursor  cursor = database.rawQuery(query,null);
    
            if (cursor != null) {
                cursor.moveToFirst();
            }
            return cursor;
    
    0 讨论(0)
  • 2020-12-31 18:44
    String selectQuery = "select * from " + TABLE;
            sqlDatabase = this.getWritableDatabase();
    
         Cursor cursor = sqlDatabase.rawQuery(selectQuery, null);
    
        if (cursor != null) {
            cursor.moveToFirst();
        }
    
    
        return cursor;
    

    this will help you..

    0 讨论(0)
  • 2020-12-31 18:46

    here you can pass value for filter on

       public ArrayList<PlayListModel> getPlaylist(String playlistName) {
        SQLiteDatabase db = this.getReadableDatabase();
        ArrayList<PlayListModel> obj = new ArrayList<PlayListModel>();
        Cursor cursor = db.query(TABLE_PLAYLIST, new String[] { KEY_ID,
                        KEY_TITLE, KEY_SINGER , KEY_PATH , KEY_PLAYLISTNAME , KEY_DUR }, KEY_PLAYLISTNAME+ "=?",
                new String[] { playlistName }, null, null, null, null);
        if (cursor != null)
            cursor.moveToFirst();
    
        PlayListModel contact = new PlayListModel
                (cursor.getString(1),
                        cursor.getString(2),cursor.getString(3),
                        cursor.getString(4),cursor.getString(5));
        obj.add(contact);
        // return contact
        return obj;
    }
    
    0 讨论(0)
  • 2020-12-31 18:49
    dbHelper = new DBHelper(getApplicationContext());
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    
    Cursor cursor = db.rawQuery("select * from centuaryTbl where email='"+email+"'",null);
    if (cursor.moveToFirst())
    {
        do
        {
            String s1 = cursor.getString(cursor.getColumnIndex("s1"));
            String s2 = cursor.getString(cursor.getColumnIndex("s2"));
            String s3 = cursor.getString(cursor.getColumnIndex("s3"));
    
    
        }while (cursor.moveToNext());
    }
    
    0 讨论(0)
提交回复
热议问题