Location of sqlite database on device

I created the sqlite database programmatically with the default SQLiteOpenHelper and override onCreate() . Thus, db is created on the fly when necessary.

I want to check the contents of a db file on my OS X machine using sqlite browser. I know the name of the db file, but I can not find it on the device. I connected to the device via USB and looked using finder and terminal, but I just can't find the db file.

What is the default location for sqlite databases on an Android device?

+75
android sqlite
Dec 15 '10 at 16:47
source share
15 answers

You can find the database you created with the name <your-database-name>

at

 //data/data/<Your-Application-Package-Name>/databases/<your-database-name> 

Extract it using File Explorer and rename it to have the .db3 extension to use it in SQLiteExplorer

Use the DDMS file explorer to navigate to the emulator directory.

+80
Dec 15 '10 at 16:58
source share

For this I did

 File f=new File("/data/data/your.app.package/databases/your_db.db3"); FileInputStream fis=null; FileOutputStream fos=null; try { fis=new FileInputStream(f); fos=new FileOutputStream("/mnt/sdcard/db_dump.db"); while(true) { int i=fis.read(); if(i!=-1) {fos.write(i);} else {break;} } fos.flush(); Toast.makeText(this, "DB dump OK", Toast.LENGTH_LONG).show(); } catch(Exception e) { e.printStackTrace(); Toast.makeText(this, "DB dump ERROR", Toast.LENGTH_LONG).show(); } finally { try { fos.close(); fis.close(); } catch(IOException ioe) {} } 

And for this, your application must have permission to access the SD card, add the following setting to your manifest. xml

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

Not a brilliant way, but it works.

+39
Oct 31
source share

A context contains many path functions: Context.getXXXPath ()
One of them is android.content.Context.getDatabasePath (String dbname), which returns the absolute path to the database named dbname.

 Context ctx = this; // for Activity, or Service. Otherwise simply get the context. String dbname = "mydb.db"; Path dbpath = ctx.getDatabasePath(dbname); 

The return path in this case will look something like this:

 /data/data/com.me.myapp/databases/mydb.db 

Note that this path is auto-generated when using SQLiteOpenHelper to open the database.

+20
Jul 10 '14 at 12:01
source share

If you are talking about a real device, /data/data/<application-package-name> not available. You must have root privileges ...

+17
Dec 15 '10 at 19:33
source share

This is an old question, but the answer may help others.

The default path in which Android saves databases cannot be connected to unloaded devices. Thus, the easiest way to access the database file (debugging environment only) is to change the class constructor:

 public class MySQLiteOpenHelper extends SQLiteOpenHelper { MySQLiteOpenHelper(Context context) { super(context, "/mnt/sdcard/database_name.db", null, 0); } } 

Remember to change the following lines for your production environment:

 public class MySQLiteOpenHelper extends SQLiteOpenHelper { MySQLiteOpenHelper(Context context) { super(context, "database_name.db", null, 0); } } 
+14
Feb 17 '14 at 15:16
source share

/data/data/packagename/databases/

t

/data/data/com.example.program/databases/

+10
Dec 15 '10 at 16:50
source share

The SQLite database is just a file. You can take this file, move it and even copy it to another system (for example, from a phone to a workstation), and it will work fine. Android stores the file in the directory /data/data/packagename/databases/ . You can use adb command or File Explorer view in Eclipse ( Window > Show View > Other... > Android > File Explorer ) to view, move or delete.

+8
Dec 16 '10 at
source share

It's good that it may be late, but it will help. You can access the database without rooting your device via adb

run adb using cmd and enter the following commands

 -run-as com.your.package -shell@android:/data/data/com.your.package $ ls cache databases lib shared_prefs 

Now you can open here.

+8
Dec 11 '13 at
source share

If you name your db as a file without specifying a path, the most common way to get its folder is:

 final File dbFile = new File(getFilesDir().getParent()+"/databases/"+DBAdapter.DATABASE_NAME); 

where DBAdapter.DATABASE_NAME is just a String like "mydatabase.db".
Context.getFilesDir() returns the path to the application files, for example: /data/data/<your.app.packagename>/files/ , so you need .getParent()+"/databases/" to delete the "files", and instead, add "databases".
BTW Eclipse will warn you about a hard-coded string "data / data /", but not in this case.

+4
Jul 07 '14 at 18:17
source share

You can access it using the adb how-to shell

Content from the above link:

Tutorial. How to access the Android database using the command line. When you start working with a database in your program, it is really important and useful to have access to it directly, outside the program, to check what the program has just done and to debug it.

And this is also important on Android.

Here's how to do it:

1) Run the emulator (or connect your real device to the computer). I usually run one of my programs from Eclipse for this. 2) Run the command prompt in the Android tool directory. 3) adb shell type. This will launch the unix shell on your emulator / connected device. 4) go to the directory where your database is located: data / data cd here is a list of all applications on your device Go to application directory (be careful, Unix is ​​case sensitive !!) cd com.alocaly.LetterGame and descent in your directory Databases: cd databases Here you can find all your databases. In my case there is only one (now): SCORE_DB 5) Run sqlite in the database you want to check / modify: sqlite3 SCORE_DB Here you can check that the tables: .tables 6) enter any required SQL command: select * from Score;

It's pretty simple, but every time I need it, I don't know where to find it.

+2
Nov 17 '12 at 21:45
source share
 By Default it stores to: String DATABASE_PATH = "/data/data/" + PACKAGE_NAME + "/databases/" + DATABASE_NAME; Where: String DATABASE_NAME = "your_dbname"; String PACKAGE_NAME = "com.example.your_app_name"; 

And check if your database is stored in the device store. If so, you should use permission in Manifest.xml:

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
+2
Feb 21 '17 at 5:47
source share

You can also check if your IDE has a utility such as the Eclipse DDMS perspective, which allows you to browse the directory and / or copy files to or from the emulator and from the root device.

0
Feb 06 '13 at
source share

Define your database name, for example:

 private static final String DATABASE_NAME = "/mnt/sdcard/hri_database.db"; 

And you can see your database in:

 storage/sdcard0/yourdatabasename.db 
0
May 23 '14 at 9:16
source share

If your application creates a database, this database is stored by default in the DATA/data/APP_NAME/databases/FILENAME. directory DATA/data/APP_NAME/databases/FILENAME.

Parts of the above catalog are based on the following rules. DATA is the path returned by the Environment.getDataDirectory () method. APP_NAME is your application name. FILENAME is the name specified in the application code for the database.

0
Jun 05 '14 at 6:03
source share

the public class MySQLiteOpenHelper extends SQLiteOpenHelper {MySQLiteOpenHelper (context context) {super (context, "/mnt/sdcard/database_name.db", null, 0); }}

Do not print "/ sdcard /"; use Environment.getExternalStorageDirectory () instead. getPath () instead

0
Feb 28 '17 at 2:18
source share



All Articles