How to access an existing sqlite database in Android? How to access an existing sqlite database in Android? sqlite sqlite

How to access an existing sqlite database in Android?


Take a look at the documentation for android.database.sqlite.SQLiteDatabase.

In particular, there's an openDatabase() command that will access a database given a file path.

SQLiteDatabase db = SQLiteDatabase.openDatabase(path, null, 0);

Just specify the path to your database as the path variable, and it should work.


I have followed the same road and found two issues:

  1. Include the _id field on any table you create and make sure it ispart of the columns to return when you query any table.
  2. You may run into an error like Failed to open the database. closingit.. This is because we are copying the database from an existingfile instead of creating tables on top of a db created by the sqliteandroid API and the table android_metadata may not exist. Forcreating it just run the following query on your db:

    CREATE TABLE android_metadata (locale TEXT);

    And add the corresponding locale, for example en_US


First copy your SDCARD and give it's path in the variable "DBNAME" in the following example.it will be something like "/sdcard/persons.db" if you are directly pulling it to sdcard.