How access existing sqlite database on Android Emulator?

22,910

Solution 1

In Eclipse Go to Window > Open Persepective > Other > DDMS. Navigate to the DB like the image from the answer below, select the database then click on the floppydisk icon to pull the file from the device on the top right.

In the emulator, the location in DDMS should be /data/data/com.yourNamespace/databases in the File Explorer tab.

enter image description here This is a pic of the DDMS perspective. In the File Explorer tab on the right, you would drill down to the databases folder. These are virtual folders, so you won't find them on your system. To examine the db, you would select the icon for Pull file from the device (sorry, it got cropped out in this screenshot) and open that file in SQLite.

Solution 2

Retrieve databse from app from cmd

->adb -e shell

--->su root

--->cd data/data/app.name.com/databases

--->cp databasename.db /sdcard/DCIM/

--->exit

--->exit

->adb pull sdcard/DCIM/databasename.db

Solution 3

In android studio run your app in emulator and click on "Device File Explorer" explore data/data/{appname}/database

Explore data/data/{appname}/database. Then right click and save your database file. That's it.

Solution 4

If you did not root your phone, only your app can access your database and it is not possible to view it through DDMS. You will need to implement a function that copies the database to the storage card (make sure you have the external storage permission). From there, you can view your database with an app like aSQLiteManager.

Alternatively, you can just use the Log method along with cursors to print out whatever information you need, but the first method will provide you with a more graphical way of perusing your database.

Solution 5

The database is created on the emulator. Should be in /data/data/[package]/databases/ You can use DDMS to navigate the emulator's filesystem and pull the database file from it to examine locally.

Or you can use sqlite3 on a shell (adb shell) to examine it.

Share:
22,910
Rob
Author by

Rob

Junior CS student at Villanova University.

Updated on March 27, 2020

Comments

  • Rob
    Rob about 4 years

    So im new to working with databases in android, and I cant seem to figure out how to view a created database.

    I created the database adapter class and in my main activity class.

    I run it in the emulator with no issues, but how do I view the contents? The book im reading says "examine the file system of the Android device/emulator using DDMS. The database is created under the database folder" and has an image of the database under a database folder in Eclipse. I dont know what the first part really means (using DDMS?) and have no idea where the /data/data folder is that people mention.

    Even running SQLite3 in CMD and typing ".tables" doesn't yield any database.

  • Rob
    Rob almost 13 years
    SQLite3 says there are no databases
  • ahmet alp balkan
    ahmet alp balkan almost 13 years
    sqlite doesn't say that. go to that folder and view contents. if file is not there, you've failed to create db.
  • ashishdhiman2007
    ashishdhiman2007 over 6 years
    I was not able to see anything in data folder, but this command helped me in pulling the db file. Thanks
  • ankurdayalsingh
    ankurdayalsingh over 6 years
    I able to pull db and using DB Browser for SQLite able to view full db architecture. Thanks Great.