Gautam Mandsorwale
Gautam Mandsorwale

Reputation: 1600

Sqlite Database storage

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?

Upvotes: 2

Views: 4325

Answers (5)

Shamsul Arefin
Shamsul Arefin

Reputation: 1917

It is stored in /data partition of internal storage, but it is usually inaccessible without superuser(root) privileges.

Upvotes: 0

AnkitRox
AnkitRox

Reputation: 544

In App memory, you can save it at data/data/pkgname/databases/mydb.db

Upvotes: 0

Sylvain Huard
Sylvain Huard

Reputation: 1398

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.

Upvotes: 0

waqaslam
waqaslam

Reputation: 68177

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);

Upvotes: 7

Goofy
Goofy

Reputation: 6128

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/

Upvotes: 1

Related Questions