Android:从数据库中获取特定行

时间:2014-06-28 05:42:59

标签: android mysql

我有一个大约200行的数据库,我想知道如何从ids 50到75获取行。我使用以下代码从数据库中检索所有行。

SQLiteDatabase db = this.getWritableDatabase();
     String selectQuery = "SELECT  * FROM " + TABLE_DETAILS;
     try {
         Cursor cursor = db.rawQuery(selectQuery, null);
         try {
             if (cursor.moveToFirst()) {
                 do {
                    Log.d("Data", cursor.getString(1));
                        Log.d("Data", cursor.getString(3)));
                    Log.d("Data", cursor.getString(4)));
                    Log.d("Data", cursor.getString(5)));
                 } while (cursor.moveToNext());
             }

         } finally {
             try {
                 cursor.close(); 
             } catch (Exception ignore) {

             }
         }
     } finally {
         try {
             db.close();
         } catch (Exception ignore) {

         }
     }

谢谢, 萨赫勒

1 个答案:

答案 0 :(得分:1)

您可以使用where语句:

 WHERE ids >= 50 AND ids <= 75