Android @ Kiowok

SQLite Database (Single Table)

At the center of the SQLite database are your tables holding the data. You do not directly access the data in the tables -- data is inserted into the database via ContentValue objects, and data is pulled from the database via Cursor objects:

Put data in a ContentValues object to move into an SQLite table; a Cursor object holds data pulled from the SQLite table.

This example will create a database containing information about movies. The main activity of the app is MovieActivity. The major components of the app are:

  • MovieActivity class
  • MovieDB class that coordinates the use of the database (references to database and database helper objects, and lots of useful methods for accessing the database).
  • SQLiteDatabase
  • DBHelper

A visualization of this structure is shown below:

A MovieActivity object has a  movieDB reference to a MovieDB object, which in turn references a SQLiteDatabase object and a DBHelper object.

Information is pulled from the database via a Cursor object

Retrieve information from the database via a Cursor object

Information is put into the database via a ContentValues object:

Insert a value into the database via a ContentValues object.

See the Java classes and the layout XML for the Movie app.

Top