Browse SQLite Database Data at Glance

Let’s make new button that will show all SQLite database data at glance in the toast.


Then, add method in MySQLiteAdapter class:


Good habit in accessing the data in SQLite database is to find column indexes first, and then to use it.
Change readAllData from void to String, and return

public void String readAllData(){

SQLiteDatabase db = helper.getWritableDatabase();

String column[] = {MySQLiteHelper.UID,MySQLiteHelper.FIRST_ROW,MySQLiteHelper.SECOND_ROW};

Cursor cursor = db.query(MySQLiteHelper.TABLE_NAME,column,null,null,null,null,null);

StringBuffer stringBuffer = new StringBuffer();

while (cursor.moveToNext())


int index_id = cursor.getColumnIndex(MySQLiteHelper.UID);

int index_first_row = cursor.getColumnIndex(MySQLiteHelper.FIRST_ROW);

int index_second_row = cursor.getColumnIndex(MySQLiteHelper.SECOND_ROW);

String name = cursor.getString(index_first_row);

String addr = cursor.getString(index_second_row);

int cursor_id = cursor.getInt(index_id);

stringBuffer.append(cursor_id + ” ” + name + ” ” + addr + ” ” + “\n”);


return stringBuffer.toString();



This is more or less all about browse SQLite database data at glance. Usage is as follows:
go to and type following code:

public void showAllData(View view) {

String allData = helper.readAllData();



Posted in android Tagged with:

Leave a Reply

Your email address will not be published. Required fields are marked *