android-sqlite Getting started with android-sqlite

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


The SQLite library itself has only a C API; to make it accessible from Java, the Android framework wraps this with the android.database.sqlite package. The most important classes are SQLiteDatabase and SQLiteOpenHelper.

The android.database package contains the database-related parts of the framework that are not SQLite specific.


API Level

API LevelPlatform VersionNameRelease Date
164.1Jelly Bean2012-07-09

Basic usage

To include a database in your app, you typically derive a class from SQLiteOpenHelper:

public class HelloDBHelper extends SQLiteOpenHelper {
    private static final int DATABASE_VERSION = 1;
    private static final int DATABASE_NAME = "hello";

    HelloDBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);

    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE ...");

This helper class is responsible for opening (and creating/updating, if needed) the database. Use it to get an SQLiteDatabase object to access the data:

SQLiteDatabase db = helper.getReadableDatabase();
Cursor c = db.query(...);
while (c.moveToNext()) {
    String name = c.getString(0);
SQLiteDatabase db = helper.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("column", value);
db.insertOrThrow("table", null, cv);

Got any android-sqlite Question?