We Code your Dreams

home > How to retrieve values from SQlite Database

How to retrieve values from SQlite Database

In the previous we have learned

how to insert values into database in Android

This program in part of the previous program

Here we will learn how to fetch values from Database
In next Artilce we are goin to learn

how to check values inserted in SqliteDatabase - Click Here

package com.example.simpledatabase;

import android.os.Bundle;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

DBhelper dbh;
SQLiteDatabase dtb; //to fire Queries

	protected void onCreate(Bundle savedInstanceState) 
		DBhelper dbh = new DBhelper(this);
		dtb = dbh.getWritableDatabase();
		Cursor cs=dtb.query("addrecord", 
new String[]
dbh.num,dbh.name}, null, null, 
null, null, null);
		int no;
		String nm;
		no = Integer.parseInt(cs.getString(0));
		nm = cs.getString(1);
"Number is : "+no+" Name is :"+nm, Toast.LENGTH_LONG).show();

//while last record is present
	} // Cursor

Label - android

by - Chinmay Mahajan

Are you looking for something else?

Suggested Programs

Working with SQlite Database in Android

How to check values inserted in SqliteDatabase

Simple Android program to insert values into Database

Simple Text-to-Speech Android App

Error while Creating New Android Project in Eclipse