This may be a stupid question to ask, but still I need to know the exact answer of it. When we create a DB for a particular app and deploy that app on a real device, where is the DB created by the system? On the internal storage or on the SD card?? If its on the internal storage by default, can we shift it to the SD card, because the app might crash due to low internal memory and increasing DB size. I have one DB with a table with 9 columns. Where would be the correct location to store the DB?
-
I think google would be the best answer to all the above qs did u try a search before posting here? – Deva Mar 29 '12 at 12:40
-
how many records you save it into database ? – Chirag Mar 29 '12 at 12:41
-
1yes I did google around but cudnt get a relevant answer. For now i havent inserted loads of records in the table. But my concern is how my app will behave in future when number of records are many. Will it crash/not respond/wont take entries etc. So I am asking this question. – Gautam Mandsorwale Mar 29 '12 at 14:34
-
Please check the below link . Might it helpful to you. http://stackoverflow.com/a/4433251/614807 – Chirag Mar 29 '12 at 12:42
5 Answers
If you dont provide any specific path during creating database using SQLiteOpenHelper
, then it will (default) store it in device's internal memory:
data/data/app_package_name/databases/dbFilename
However, you may provide your own path/ location too when creating database, for e.g.
/*creating database in SD card under app's cache directory*/
context.openOrCreateDatabase(context.getExternalCacheDir() + "/dbFileName",
Context.MODE_PRIVATE, null);

- 67,549
- 16
- 165
- 178
-
so if the DB is in the internal memory by default, wont it hamper the performance of my app, since internal memory isnt large enough...??? – Gautam Mandsorwale Mar 29 '12 at 14:37
-
1In fact performance is always better when using internal memory because it takes extra time to read and write on SD card (depending on the Class of card). And internal memory shouldn't be a matter for general use or intermediate level apps unless your app is not generating thousands of records. You can keep track of you app's cache by looking into **Applications** under **Settings**. For reference, i created a dictionary which had almost 100000 records (including primary_key auto_increment ID fields and a lot other extra grammatical stuff) and it took almost 6MB of space in SQLite – waqaslam Mar 29 '12 at 16:41
try getDatabasePath on ContextWrapper ( http://developer.android.com/reference/android/content/ContextWrapper.html ). If you are in an Activity or Application class try:
File dbFile = getDatabasePath(MY_DB_NAME); Log.i(dbFile.getAbsolutePath());
Edit
also see in this /data/data/packname/databases/

- 6,098
- 17
- 90
- 156
-
my concern is how my app will behave in future when number of records are many. Will it crash/not respond/wont take entries etc. So I need some guidance as to how should I go wth my DB maintenance.. – Gautam Mandsorwale Mar 29 '12 at 14:35
I'm facing a similar problem that answers your crash question. I ported Gingerbread to my custom system and need to use a SQLITE database. It is by default where "Waqas" previously said. Since the code I'm using was written by someone else, I did not know all of that and I was always getting in the logs some SQLite errors. My internal flash was space limited and I ran out of it without knowing. My application that was downloading information from a server was just reporting that the download did not succeed. Going through the different logs, I found that some SQLITE errors occurred but nothing telling me "disk full". I guess this is too low level for an Android application level. Hope it answers your question about the crash. The system does not crash but your application will suffer.

- 1,378
- 6
- 18
- 29
It is stored in /data partition of internal storage, but it is usually inaccessible without superuser(root) privileges.

- 1,771
- 1
- 21
- 21