2

I would ask you on your opinion, what is the best way to import data into SQLite database.

  1. Create SQL dump and put it into assert folder and use rawQuery() method to execute.
  2. Each table create independent and data read from csv/xml documents
  3. Copy complete database, using InputStream/OutputStream

    • If size of data is approximately 1MB / 2000 recors, and less
    • if size of data is >= 1MB

Thank you

Peter Jurkovic
  • 2,686
  • 6
  • 36
  • 55

3 Answers3

0

I often create a JSON file and place it in the assets dir. I then use a library like GSON to extract the contents into model classes so i can access the data in an object oriented way. You could then insert/update the database using the data accessed via the model classes

james
  • 26,141
  • 19
  • 95
  • 113
0

Copying the original SQLite db file is the easiest way.Just make sure the files are compatible with SQLite version on android. You can also open these file from third party tools like SQLiteMan

S.D.
  • 29,290
  • 3
  • 79
  • 130
0

Copy the SQLite database to your assets folder (you could even gz it to preserve precious space on some devices, you can unzip it with 'GZIPInputStream'. The only drawback of this approach is that a file in the assets folder cannot be larger than a few MiB's (I think 3, but it might vary per device). To use a larger file, change the extension of the database file (or gz file if you zipped it) to '.mp3' and you can use a file larger than the 3 MiB.

Toverbal
  • 256
  • 3
  • 14