Ofir A.
Ofir A.

Reputation: 3162

Load large amount of data to DB - Android

I'm building a new application to the Android platform and I need a suggestion. I have a large amount of data that I want to import into a sqlite DB, something like 2000 rows. My question is what is the best method to load the data into the DB?

Two ways I think of:

  1. An xml file that holds all the data and then loads it with DocumentBuilder object.
  2. A CSV file, and loads it with String Tokenizer. Found that post.

I want it to be with external file because When I release an update I will replace only the that file.

I want something that would be efficient as much as possible - all the data will load at the first startup of the application and I need it to be fast.

Any suggestion would be great. Thanks.

Upvotes: 1

Views: 3000

Answers (3)

lujop
lujop

Reputation: 13873

Use InsertHelper to do a bulk insert. Take a look on this other question

Upvotes: 3

Konstantin Pribluda
Konstantin Pribluda

Reputation: 12367

It really does not matter - you can achieve good perfomance with both approaches. With XML you can use some databinding, making programming easier (marginally). You may also consider JSON as transport format.

When parsing, keep in mind that building complete object tree in memory ( like XML DOM parser) consumes a lot of memory and results in a lot of allocations - pull parsing model like XPP / GSON is preferable.

Upvotes: 3

Hakan Serce
Hakan Serce

Reputation: 11256

Instead of XML or CSV files, you can directly use an external sqlite DB you prepared in your computer. This technique is explained here: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

Upvotes: 3

Related Questions