Ron Gross Ron Gross - 5 months ago 34
Android Question

Android sqlite from pc

I have a pre-baked sqlite database that I want to use in my Android application.

I've followed this tutorial:

However nothing is throwing an exception during the process of building and copying the db,
but when I access the db tables, they are not there, like they don't exist.

I made this sql query:

database.rawQuery("SELECT * FROM sqlite_master", null).getCount();

and I got the answer: 1. (I have 5 tables)

Any help?


That tutorial there is too old. Try the following steps:

1) Create a class that extends SQLiteOpenHelper and overwrite the onCreate() and onUpgrade() methods

2) In some Activity instantiate your class, created in 1) and that's it - you will have your database created under data/data/YOUR_PACKAGE/databases/

3) If you want after that, you may obtain writable instance from the class created in 1) (getWritableDatabase()) and execute insert statements towards your database to populate it with data. Wrap your data in ContentValues and use insertOrThrow(your_table_name, null, your_content_values).

Hope that helps.