Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON file VS SQLite android

Tags:

I will develop an android application with a lot of data (json files with some rows and CSV for graphics data with a lot of rows) , this data change every 5 minutes and replaces all the previous data (or mostly).

What are the best approaches to design this ? I have 2 options:

  • Save all the data in a sqlite db, and sync this by a IntentService.

  • save the data in json and csv files and replace this every 5 minutes.

Which approach will the best performance? This considering the time to parse the files, sorting data, the download time and the consistency of data.

any other ideas?

PD:I need a cache system too, in case if i don't have internet and I need the previous stored data

like image 752
Rodrigo Amaro Reveco Avatar asked Dec 28 '11 04:12

Rodrigo Amaro Reveco


People also ask

Which is faster JSON or SQLite?

Json is actually very commonly used for storing data, SQLite is better if the data can be broken to multiple separate tables with connection.

Is SQLite a JSON?

Interface Overview. SQLite stores JSON as ordinary text. Backwards compatibility constraints mean that SQLite is only able to store values that are NULL, integers, floating-point numbers, text, and BLOBs. It is not possible to add a sixth "JSON" type.

What is the alternative of SQLite in Android?

But if you want to replace SQLite completely, there are also quite a few alternative databases: Couchbase Lite, Interbase, LevelDB, Oracle Berkeley DB (formerly Oracle's mobile database was "Oracle Database Lite"), Realm, SnappyDB, Sparksee Mobile (graph database, brand-new at the time of this article), SQL Anywhere, ...

Is SQLite good for Android?

SQLite Database is an open-source database provided in Android which is used to store data inside the user's device in the form of a Text file. We can perform so many operations on this data such as adding new data, updating, reading, and deleting this data.


2 Answers

Advantages of SQLite:

  • Changes are ACID
  • You can make complex requests faster (e.g. "give me only fields A,B from items with (C/D)>E")
  • I would bet more compact for big data (integers are stored as integers instead of a string of individual digit)
  • Only one file
  • You can merge old data with new data easily
  • You can update current data, even while using it
  • Concurrency can be handled

Advantages for JSON/CSV:

  • Easier to debug (plain text)
  • Faster to make a whole update (copy the new file + delete the old one)

For the original question the whole delete/replace of the data makes JSON/CSV the winner.

However, if the application was to retrieve partial data every 10s and merge/update it with the previous one, SQLite would be a better option.

like image 198
ofaurax Avatar answered Sep 19 '22 15:09

ofaurax


Sqlite is mostly used when you want data to be saved and used in future. In your case data is changing every 5 minutes so its better to have JSON because every time to make the Database connection store and retrieve after 5 minutes will take some time.

UPDATE:

I also had the same Application in which the data was changing every time. In that case I used Map<K, V> and ArrayList to maintain the values, because as the data is changing everytime I think its not feasible to store the data in Sqlite everytime. It needs much time to perform DB Connection store, retrieve, update the data in Sqlite.

like image 37
Lalit Poptani Avatar answered Sep 18 '22 15:09

Lalit Poptani