Cursor cursor = db.query("mytable", null, null, null, null, null, null); if (cursor.moveToFirst()) { short myShortValue = cursor.getShort(cursor.getColumnIndex("my_column_name")); }
Cursor cursor = db.query("mytable", new String[]{"column1", "column2"}, null, null, null, null, null); while (cursor.moveToNext()) { short value1 = cursor.getShort(cursor.getColumnIndex("column1")); short value2 = cursor.getShort(cursor.getColumnIndex("column2")); }In this example, we retrieve only two columns ("column1" and "column2") from the "mytable" table using a `String` array as the second argument to the `query()` method. We then loop through all rows of the result set and retrieve the values of each column as shorts using `getShort()`. The `Cursor` class is part of the `android.database` package library.