I'm new to Android, I've just gotten to the point where I can create an SQLite database from my app (I'm using Eclpise with Android SDK and the emulator, I made the SQL code in a separate designer and then just pasted it). After getting rid of a few initial errors, the SQLiteOpenHelper-descendant class initialization code ran without any exceptions, so I'm assuming the database has been created (and presumably persisted in a file). Is there a way I could access the database and examine it? (I mean other than from the actual app, which at this point has no functionality to speak of) I'd like to have a look at the database structure, and later when the app gradually becomes capable of adding data, I'd like to be able to chcek if it's working properly. Is there a way to do this? Thanks.
6 Answers
Here is what I do (I'm running Windows 7):
- A batch file that pulls the database file from the device / emulator to my local filesystem:
Here is the content of that batch file:
cd C:\Development\Android\android-sdk\platform-tools
adb pull /data/data/<your package name>/databases/<your database file name> <your local path>
- And once it's in my local filesystem, I open it with SQLitebrowser, a nice free Windows graphical client for SQLite. Find more details and download the latest version at http://sqlitebrowser.sourceforge.net and http://sourceforge.net/projects/sqlitebrowser/
- 22,434
- 14
- 55
- 70
-
1Note that after editing the database using SQLite Database Browser as above, you can push back to the device using the equivalent method: cd C:\Development\Android\android-sdk\platform-tools adb push
\ – Warren Sergent May 12 '13 at 20:42/data/data/ /databases/ I simply save the two bat files as pull.bat and push.bat to retrieve and edit my database before returning it to the device.
You can access the SQLite Data through the DDMS included in Android SDK and integrated in Eclipse.
In this link they say how to do this.
First you have a command-line tool described here. Personally I am not a fan of command-line tools so I use MOTODEV plug-in for Eclipse (though you have to register to download it). It has a Database perspective capable of manipulating your SQLite db.
- 5,586
- 1
- 32
- 31
Open Eclipse Go To Window > Showview > Other.. > File Expolrer Click On Open
Now Go To
data/data/your.package.name/databases/<DATABASE FILE Here >
Now Click On Pull File From Device Which Is Right Side On Top
Save That File To Anywhere In Your PC Then
Use the SQLite database browser to explore stored data.
You have a couple of choices:
- While the emulator is running, inside Eclipse, go to Window -> Show View -> Other.. -> Android -> File Explorer and then data/data/(Search your App_name)/databases
- Copy the db to the sd card, move it to your computer and view it there. For code to do this, see one of my other posts here: Is it possible to save database file to SD card?
For #1, don't forget that the emulator needs to be running. For #2, I've found that the SQLite Manager for Firefox is a great tool for viewing the db.
-
Thanks, I found the database using the first option, but all it tels me is that it's there. There are 2 items, on has my database's name and size of 5120, the other one is named data and has 0 size (there isn't any data in the database yet) I haven't found a way to open those items and browse the contents. Can that be done? – Shaggydog Oct 13 '11 at 16:54
-
In the the File Explorer view, there is an icon at the upper right hand corner that allows you to pull the file from the emulator and save it. Do that, and then use the SQLite Manager firefox plugin to view it. – SBerg413 Oct 13 '11 at 17:57