Tag Archives: emulator

How to connect to database on Android emulator (at OSX)?

1. Run your emulator and check the port on which he’s running.

2. Connect to the emulator via shell (terminal)

Use command:

$ adb -s <emulatorId> shell

My example:

$ adb -s emulator-5554 shell

Hint: to list all active emulators use command:

$ adb devices

3. Each Android database is hold in a file .

The path pattern to your db file is (while you connected to emulator):

# /data/data/<your_app_package>/databases

So just go there to see your databases, in my example it looks like this:

# cd /data/data/com.example.application/databases
# ls EXAMPLE_DATABASE

4. Open your database.

So now, while I know which db I want to open I do this:

# sqlite3 /data/data/net.hopbit.dev.myapplication/databases/MY_EXAMPLE_DATABASE
SQLite version 3.6.22
Enter „.help” for instructions
Enter SQL statements terminated with a „;”

5. Manage your DB and execute queries

Now, when I’m connected to my database I can manage my db and execute some queries, here’s example:

sqlite> .tables
NOTES_TAB    USERS_TAB
sqlite> select * from users_tab;
LOGIN|NAME|SURNAME
test1|Test|One
test2|Test|Two

 


Resources:
* Android Debug Bridge | Android Developers
* Command Line Shell For SQLite

Share this article

  • Blip
  • Delicious
  • Digg
  • Facebook
  • Grono
  • Kciuk
  • NK
  • Twitter
  • Wykop