import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor cursor = db.rawQuery("SELECT id, name FROM people", null); if (cursor.moveToFirst()) { do { int id = cursor.getInt(cursor.getColumnIndex("id")); String name = cursor.getString(cursor.getColumnIndex("name")); Log.i("Person " + id, "Name: " + name); } while (cursor.moveToNext()); } cursor.close();
import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor cursor = db.rawQuery("SELECT p.id, p.name, c.name FROM people p JOIN countries c ON p.country_id=c.id", null); if (cursor.moveToFirst()) { do { int id = cursor.getInt(cursor.getColumnIndex("id")); String name = cursor.getString(cursor.getColumnIndex("name")); String country = cursor.getString(cursor.getColumnIndex("c.name")); Log.i("Person " + id, "Name: " + name + " Country: " + country); } while (cursor.moveToNext()); } cursor.close();This code performs a join between the people and countries table and logs the id, name and country for each person. Package Library: android.database