Debugging database

SDK Version: 

When I first tried to manage an sqlite database on an android device I was not sure about where I fail in it. Can I even insert the records into the database, or I fail only to read the data from it? So I started to search for possibilities to debug the database lifecycle.

The system stores databases in the /data/data/package_name/databases folder by default.

In a command line using the adb (Android Debug Bridge - found in the android sdk tools library) you can access the databases on a running emulator like below:

  1. adb -s emulator-5554 shell
  3. sqlite3 /data/data/package_name/databases/database_name

After this you can type normal SQL commands to test the content. For example:

  1. SELECT * FROM table_name;

This will list the table content (in an ugly format), or say that it does not exists.

The sqlite3 command will not give an error if the database itself does not exists, it will be created. So you wont notice if the database creaton was unsuccessfull in yuor application, or you simply did a typo in the command.

It is also not too effective to test everything by having to write SQL statements, so lets see a moore user frendy way, using graphical tools, to look into the database.

We will use DDMS ( Dalvik Debug Monitor Server - from the android sdk too) through Eclipse and SQLite Database Browser.

First run yuor application on a virtual device, then open the DDMS perspectine in Eclipse. window/open perspective/other... Then select DDMS.

open DDMS

In the DDMS perspective the running emulator is showed, after selecting it you can list the file system of the virtual device.


Here simply select the database defaultly in /data/data/package_name/databases/ then press the button near the top right of the file explorer to "pull a file from the device". (If the application is still running an the emulator it probably prevents the pulling, beacause using the file, so leave the application it this problem occurs)

pull the file

The last part is to open the pulled database file using the SQLite Database Browser, where you can easily check its structure and content on a graphical interface.

pull the file