0

Possible Duplicate:
How to ship an Android application with a database?

I'm trying to develop an app that needs to read data from a database and display it to the user. Perhaps in the future I could add an option for users to leave comments on various articles, for which I'll need a server instead of SQLite right? But for reading data is it better to have a local database with 3k to 5k records in each table?

Secondly I'm a total newbie when it comes to Android and databases. I've dealt with PHP+MySQL but it's not quite the same. Since the records are a lot, I'd like to enter them from a back-end (sqlitebrowser) and copy the file from assets folder (done this already). I've tried creating a database helper class using tutorials online but that didn't work at all for me. I also tried creating a connection profile in Eclipse which kinda works when I tried using the SQL Scrapbook view. It doesn't give errors, but select query doesn't show anything in SQL Results

Remember I do not want to create a new database, just copy the existing one from Assets to data/data/my.package/databases/ and read from there.

Community
  • 1
  • 1
Resley Rodrigues
  • 2,218
  • 17
  • 17

2 Answers2

2

The Android implementation of SQLite requires two conventions for the data base file. If you don't follow these conventions, Android's SQLite library won't read the data base correctly.

  1. Every table must have an INTEGER PRIMARY KEY field named _id. (This may just be standard SQLite stuff.)

  2. The data base must have a table named android_metadata. This table must have a TEXT column named locale and it should have one row with the locale name for the data. The value "en_US" works for me. Schema:

            CREATE TABLE android_metadata (locale TEXT)

Make sure that the data base in your assets conforms to these conventions.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • I've done this too. Had followed a tutorial from the same site in the post by @Ram but it didn't seem to work for me. – Resley Rodrigues Dec 22 '12 at 11:38
  • @ResleyRodrigues - The only other suggestion I have is to write and run a little Android program that just builds your data base, use `adb pull` to retrieve the file, and package that file with your app. If that doesn't work, then you know the problem is not with the data base file itself but rather with the code that installs it when it is bundled with your real app. If that's the case, post the relevant code and someone should be able to help. – Ted Hopp Dec 22 '12 at 23:19
0

The following site provides all your needs.Using your own SQLite database in Android applications

Ramprasad
  • 7,981
  • 20
  • 74
  • 135