How Do I View The SQLite Database On An Android Device - Stack Overflow
How Do I View The SQLite Database On An Android Device - Stack Overflow
- Stack Overflow
I have a set of data in an SQLite database. I need to view the database on a device. How do I do that?
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Try cordova-sqlite-detools , an open source CLI used to pull a sqlite database from a connected Android
device. npmjs.com/package/cordova-sqlite-devtools – Justin Lettau Jun 10 at 14:37
I found a quick way to perform this by simply using Google Chrome and here is it's
video.youtube.com/watch?v=fvkddnn9yps – Harpreet Oct 6 at 13:28
20 Answers
Here are step-by-step instructions (mostly taken from a combination of the other answers).
This works even on devices that are not rooted.
Notice: com.yourpackge.name is your application package name. You can get it from the
manifest file.
3. Copy the database file from your application folder to your SD card.
Notice: filename.sqlite is your database name you used when you created the database
https://stackoverflow.com/questions/19194576/how-do-i-view-the-sqlite-database-on-an-android-device 1/10
2/11/2017 How do I view the SQLite database on an Android device? - Stack Overflow
This will copy the database from the SD card to the place where your ADB exist.
1 It worked, but I had to replace single quotes in step 2 with double quotes. It doesn't work with single quotes,
but works with double quotes (at least on Windows). – Viachaslau Tysianchuk Mar 7 '14 at 21:10
1 adb pull /sdcard/ will pull whole sdcard. use adb pull /sdcard/filename.sqlite – Muneeb Mirza Dec 16 '14 at
8:08
2 it doesn't work on all devices (for example Nexus 9). For those I recommend this solution
stackoverflow.com/a/29257875/291427 – kmalmur Mar 25 '15 at 14:21
4 It's also important to note that if you want to copy the DB to your SDcard, your App (the one you're "running
as") needs the android.permission.WRITE_EXTERNAL_STORAGE -permission. Otherwise, it'll tell you
"permission denied". – Lukas Knuth Jun 30 '15 at 14:10
4 Just wanted to mention that I couldn't 'cat' the file to the sdcard and instead had to 'cp' it there, otherwise I
would get an empty file in the sdcard. – TheIT Mar 11 '16 at 1:28
The best way to view and manage your Android app database is to use the library
DatabaseManager_For_Android.
It's a single Java activity file; just add it to your source folder. You can view the tables in your
app database, update, delete, insert rows to you table. Everything from inside your app.
When the development is done remove the Java file from your src folder. That's it.
You can view the 5 minute demo, Database Manager for Android SQLite Database .
1 Thanks.Let me know if you have any trouble using the library – user3716835 Sep 24 '14 at 15:23
Can this be used to view any database (in sqllite) or only the one created by your app? – Jasper Feb 10 '15
at 11:48
Only the one created by your app – user3716835 Feb 10 '15 at 23:23
this works with SQLiteAssetHelper as well. great tool! – Rm558 Jan 12 '16 at 1:21
In build.gradle:
dependencies {
// Stetho core
compile 'com.facebook.stetho:stetho:1.5.0'
//If you want to add a network helper
compile 'com.facebook.stetho:stetho-okhttp:1.5.0'
}
Stetho.initializeWithDefaults(this);
https://stackoverflow.com/questions/19194576/how-do-i-view-the-sqlite-database-on-an-android-device 2/10
2/11/2017 How do I view the SQLite database on an Android device? - Stack Overflow
Yair Kukielka
5,317 1 18 27
5 This was too easy! What a brilliant tool, thank you Stetho developers. – Anton Nov 11 '16 at 14:15
Its incredibly simple to use and setup, just add the dependence and connect to the device
database's interface via web. No need to root the phone or adding activities or whatsoever.
Here are the steps:
STEP 1
Add the following dependence to your app's gradle file and run the application.
debugCompile 'com.amitshekhar.android:debug-db:1.0.0'
STEP 2
Open your browser and visit the your phone's IP address on port 8080. The url should be like:
http://YOUR_PHONE_IP_ADDRESS:8080 . You will be presented with the following:
To get myphone's IP I currently use Ping Tools, but there are a lot of alternatives.
STEP 3
That's it!
2 the best solution of all the others, by far... – i31nGo Sep 5 at 2:27
If you are using a real device, and it is not rooted, then it is not possible to see your database
in FileExplorer , because, due to some security reason, that folder is locked in the Android
system. And if you are using it in an emulator you will find it in FileExplorer , /data/data/your
package name/databases/yourdatabse.db.
https://stackoverflow.com/questions/19194576/how-do-i-view-the-sqlite-database-on-an-android-device 3/10
2/11/2017 How do I view the SQLite database on an Android device? - Stack Overflow
edited May 26 '16 at 12:44 answered Oct 5 '13 at 7:08
Peter Mortensen Abhijit Chakra
11.4k 16 79 106 1,833 15 39
3 I have rooted, but data in file explorer still empty – John Nov 5 '15 at 2:09
Root means you have superuser access..Like admin access in windows – Abhijit Chakra Apr 20 '16 at 10:21
1. adb shell
2. cd /go/to/databases
3. sqlite3 database.db
4. In the sqlite> prompt, type .tables . This will give you all the tables in the
database.db file.
5. select * from table1;
Thanks Mahsa Mohammadkhani, updated step 4, as you mentioned in step 2, path is app data path. –
Deepu Aug 18 '16 at 14:04
This works. Kinda. After step 1 you should do a 'run-as PACKAGE.NAME' otherwise you won't have read
access. – Mark Gjøl May 1 at 11:54
This is the correct answer. Ok, not the correct answer, but the simplest answer by far, and works as magic. –
fiatjaf 8 hours ago
Try AndroidDBvieweR!
2 Good app, but you need to add a dependency to the app's build.gradle file. – Henrique de Sousa Mar 3
'16 at 11:23
1 Which adding the dependency takes all of 5 seconds. Thanks so much Peter this is brilliant! –
LifeQuestioner Aug 10 '16 at 16:19
1 not everyone wants to add third party libraries to a project. Especially because this requires to change your
https://stackoverflow.com/questions/19194576/how-do-i-view-the-sqlite-database-on-an-android-device 4/10
2/11/2017 How do I view the SQLite database on an Android device? - Stack Overflow
code. – Alberto M Sep 8 '16 at 14:05
1. adb
2. 3rd party library or
3. gradle dependency etc
and just want the database file in your SDCard, this is the solution.
package com.util;
import android.content.Context;
import android.os.Environment;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
/**
* Shayan Rais (http://shanraisshan.com)
* created on 8/17/2016
*/
public class DatabaseUtil {
//You need to declare permission
// <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
//in your Manifest file in order to use this class
//__________________________________________________________________________________________
//__________________________________________________________________________________________
.
.
and simply call copyDatabaseToExtStg() method from any activity in your app
https://stackoverflow.com/questions/19194576/how-do-i-view-the-sqlite-database-on-an-android-device 5/10
2/11/2017 How do I view the SQLite database on an Android device? - Stack Overflow
shanraisshan
1,343 8 26
Although this doesn't view the database on your device directly, I've published a simple shell
script for dumping databases to your local machine:
https://github.com/Pixplicity/dbdump
1. First, it tries to make the file accessible for other users, and attempting to pull it from the
device.
2. If that fails, it streams the contents of the file over the terminal to the local machine. It
performs an additional trick to remove \r characters that some devices output to the
shell.
From here you can use a variety of CLI or GUI SQLite applications, such as sqlite3 or
sqlitebrowser , to browse the contents of the database.
very confused... you should explain where to put your files, and how to execute those commands... I made
copy/paste in my project, open cmd and run humpty.sh -d com.mypak.name databases/MyDB.db it says
Succes! ... but in dumps/com.mypak.name/databases folder is just a bat file witch says : run-as: Package
'com.mypak.name' is unknown – Choletski Aug 6 '15 at 11:46
@Choletski It shouldn't be outputting a batch file, that sounds like a bug. How are you executing a shell
script on Windows? Through cygwin or mingw? As for extracting the database, you may want to execute the
commands through adb shell yourself to see if your device supports run-as . – Paul Lammertsma Aug 6
'15 at 11:53
1 Works like a charm. Surprized no one upvoted this!! Thanks ! – everydayapps Oct 8 '15 at 14:47
I have been using SQLite Database Browser to see the content SQLite DB in Android
development. You have to pull the database file from the device first, then open it in SQLite DB
Browser.
I need to where the database file is present.I have checked it in file explorer but data is empty.then where to
get the database file. – user Oct 5 '13 at 6:14
Are you using emulator or real device? If on real device, then I guess DDMS won't list the internal storage
(including /data). However, you can use adb pull path_to_db_file_in_device path_to_save to save it to
computer. – Andrew T. Oct 5 '13 at 6:20
This won't work when pulling db from a real device as it will be encrypted. If anyone knows how to use this
technique with a "real" database please let me know! – Nicholas Kreidberg Jul 25 at 17:32
Stetho is a debug bridge for Android applications, enabling the powerful Chrome Developer
Tools and much more.
https://github.com/facebook/stetho
Using Terminal First point your location where andriod sdk is loacted
https://stackoverflow.com/questions/19194576/how-do-i-view-the-sqlite-database-on-an-android-device 6/10
2/11/2017 How do I view the SQLite database on an Android device? - Stack Overflow
eg: C:\Users\AppData\Local\Android\sdk\platform-tools>
adb devices
and then run this command to copy the file from device to your system
Android\sdk\platform-tools\tempDB\databases
step 2 put the following code in your class which extends SQLiteOpenHelper.
try{
String maxQuery = Query ;
//execute the query results will be save in Cursor c
Cursor c = sqlDB.rawQuery(maxQuery, null);
alc.set(1,Cursor2);
if (null != c && c.getCount() > 0)
{
alc.set(0,c);
c.moveToFirst();
return alc ;
}
return alc;
}
catch(SQLException sqlEx)
{
Log.d("printing exception", sqlEx.getMessage());
//if any exceptions are triggered save the error message to cursor an return the
arraylist
Cursor2.addRow(new Object[] { ""+sqlEx.getMessage() });
alc.set(1,Cursor2);
return alc;
}
catch(Exception ex)
{
Log.d("printing exception",ex.getMessage());
//if any exceptions are triggered save the error message to cursor an return the
arraylist
Cursor2.addRow(new Object[] { ""+ex.getMessage() });
alc.set(1,Cursor2);
return alc;
}
}
<activity
android:name=".database.AndroidDatabaseManager"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"/>
step 4
https://stackoverflow.com/questions/19194576/how-do-i-view-the-sqlite-database-on-an-android-device 7/10
2/11/2017 How do I view the SQLite database on an Android device? - Stack Overflow
Intent i = new Intent(this, AndroidDatabaseManager.class);
startActivity(i);
2>Put the *.jar file into the folder eclipse/dropins/ and Restart eclipse.
6>Underneath the DDMS icon, there should be a new blue icon of a Database light up when
you select your database. Click it and you will see a Questoid Sqlite Manager tab open up to
view your data.
*Note: If the database doesn't light up, it may be because your database doesn't have a *.db
file extension. Be sure your database is called [DATABASE_NAME].db
Then you simply can view the DB with aSQLiteManager for instance.
You can try SQLiteOnWeb. It manages your SQLite database in the browser.
I can't get gradle to resolve the dependencies listed in this project's readme – Jerec TheSith Apr 18 '16 at
10:45
Oh~, could you tell me what error you get? – NovemberEleven Apr 19 '16 at 6:27
This is brilliant! So easy to use. Thanks for sharing. – Jaimy Jun 14 '16 at 8:04
There is TKlerx's Android SQLite browser for Eclipse, and it's fully functional alongside Android
Studio. I'll recommend it, because it is immensely practical.
https://stackoverflow.com/questions/19194576/how-do-i-view-the-sqlite-database-on-an-android-device 8/10
2/11/2017 How do I view the SQLite database on an Android device? - Stack Overflow
To install it on Device Monitor, just place the JAR file in [Path to Android SDK
folder]/sdk/tools/lib/monitor-[...]/plugins .
Using file explorer, you can locate your database file like this:
data-->data-->your.package.name-->databases--->yourdbfile.db
Then you can use any SQLite fronted to explore your database. I use the SQLite Manager
Firefox addon. It's nice, small, and fast.
For rooted device also it works fine – r4jiv007 Nov 4 '15 at 9:56
3 data in file explorer still empty even device is rooted – John Nov 5 '15 at 2:11
I wrote own script for get DB file from device. Without root. Working OK.
Usage: ./getDB.sh -p <packageName> -n <name of DB> -s <store in mobile device> for get DB file
to this (where script is executed) directory.
I recommend you set filename of DB as *.sqlite and open it with Firefox addon: SQLite
Manager.
(It's a long time, when i have written something in Bash. You can edit this code.)
#!/bin/sh
# Get DB from Android device.
#
Hoption=false
Poption=false
Noption=false
Soption=false
Parg=""
Narg=""
Sarg=""
#-----------------------FUNCTION--------------------------:
helpFunc(){ #help
echo "Get names of DB's files in your Android app.
Usage: ./getDB -h
./getDB -p packageName -n nameOfDB -s storagePath
Options:
-h Show help.
-p packageName List of databases for package name.
-p packageName -n nameOfDB -s storagePath Save DB from device to this directory."
}
#--------------------------MAIN--------------------------:
https://stackoverflow.com/questions/19194576/how-do-i-view-the-sqlite-database-on-an-android-device 9/10
2/11/2017 How do I view the SQLite database on an Android device? - Stack Overflow
while getopts 'p:n:s:h' options; do
case $options in
p) Poption=true
Parg=$OPTARG;;
n) Noption=true
Narg=$OPTARG;;
s) Soption=true
Sarg=$OPTARG;;
h) Hoption=true;;
esac
done
#echo "-------------------------------------------------------
#Hoption: $Hoption
#Poption: $Poption
#Noption: $Noption
#Soption: $Soption
#Parg: $Parg
#Narg: $Narg
#Sarg: $Sarg
#-------------------------------------------------------"\\n
#echo $# #count of params
exit 0;
https://stackoverflow.com/questions/19194576/how-do-i-view-the-sqlite-database-on-an-android-device 10/10