Android Basics – Learn how to get a reference to the Database

In the last lecture you learnt how to query your database. In order to query or perform any operation on the database you need to get a reference to it.

This can be done using getReadableDatabase() or getWritableDatabase()

Refer to the sample code below, in which these methods are used to get the SurveyDBHelper object in MainActivity class

SurveyDBHelper surveyDBHelper = new SurveyDBHelper(this);
SQLiteDatabase db = surveyDBHelper.getReadableDatabase();

Follow the video to understand this better. You can refer to the source code here.

Author: androidsmartly

I am a Tech Enthusiast who likes to work on new Ideas. Sharing knowledge on Android, Marketing, Startups and More.

1 thought on “Android Basics – Learn how to get a reference to the Database”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s