Reputation: 43
I am developing a simple android application with an activity that displays some data from couple of tables in an online mySQL DB. The tables I'm reading from are not complicated and wont have more than 100 rows.
I want this app to run offline too so I'm thinking to save the data locally as soon as it gets updated in JSON format instead of going into the process of creating SQLite DB for such simple tables.
Is there any problem in that? And why everybody is using a database even for simple data storage?
Upvotes: 1
Views: 1864
Reputation: 25873
When developing software, you must take into account what might happen in the future with your I/O data, both in its structure and its size.
Even if now your data is small, it might not be in the future. So if you use files as storage, you might possibly have to move to a DB later in the future. So to avoid this, most people choose to use DB right away and avoid having future problems with data size, since a DB will work much faster and reliable (e.g. reference integrity) than a plain text file, specially if the data is of a certain size.
Also a DB is quite more flexible in its structure, and changing the structure is easy (well, at least easier than with files). This is not the case for a file, where if you want to change the structure of the file, you have to re-write the whole file loading code, which is quite more cumbersome than rewriting a couple of SQL statements.
Upvotes: 1
Reputation: 11669
The fact is, you have to know what constraints will be on your data. As @njzk2 said in the comments, serializing you data (with JSON) is much easier, but you won't have any guaranties on your data. Using a database allows you to be sure of the atomicity of your operations (you won't be doing operations at the same time on the data that risks adding errors), and, with the help of things like primary keys or foreign keys, also ensures the consistency of your data.
So you'll just have to see if you need these constraints or not to choose how to save your data.
Upvotes: 1
Reputation: 2491
you can use file to store the json o/p and can parse json locally from that file no need of db
Upvotes: 0