Chowza Chowza - 1 year ago 202
Android Question

How to use ADB in Android Studio to view an SQLite DB

I need to view my SQLite db but I don't know how to do it. I've gone to and downloaded the command line shell for my os, but when I run the program and type 'adb ...' I get errors.

I know this is a super newby question but I just don't know how to get ADB to work so I'm really hoping for some assistance...For the record I've googled this a ton but none of the answers I found were thorough enough for me to understand...

Thank you!

PS I'm using Android Studio so I'm assuming I don't need to install anything extra because I recall Android Studio said it had all the SDK tools needed ...

Answer Source

Easiest Way: Connect to Sqlite3 via ADB Shell

Note: This method requires ROOT on the device you're adbing to

I haven't found any way to do that in Android Studio, but I access the db with a remote shell instead of pulling the file each time.

Find all info here:

1- Go to your platform-tools folder in a command prompt

2- Enter the command adb devices to get the list of your devices

C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb devices
List of devices attached
emulator-xxxx   device

3- Connect a shell to your device:

C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb -s emulator-xxxx shell

4- Navigate to the folder containing your db file:

cd data/data/<your-package-name>/databases/

5- run sqlite3 to connect to your db:

sqlite3 <your-db-name>.db

6- run sqlite3 commands that you like eg:

Select * from table1 where ...;

Note: Find more commands to run below.

SQLite cheatsheet

There are a few steps to see the tables in an SQLite database:

  1. List the tables in your database:

  2. List how the table looks:

    .schema tablename
  3. Print the entire table:

    SELECT * FROM tablename;
  4. List all of the available SQLite prompt commands:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download