Introducing Android Debug Bridge – Part II

This entry is part 28 of 50 in the series Android Development Primer

In the part I of this post, I gave you a brief explanation of what ADB is and what is it used for. Although, ADB is a very effective tool and is used in numerous fields of Android Development, we are going to focus on only one which is, using ADB to query our Databases.
It is most likely that you have the previous application on your disk where we had created a database. If not, follow this post, and create one.

Now, to start off follow the steps:

  • Launch Command Prompt and navigate to the platform-tools directory inside your SDK directory. This is where adb.exe is located
  • Launch the ADB shell by typing:
    adb shell
  • Each line should now start with a “#”.
  • If you can recall, I have told you in my earlier posts that all databases of an application is located in
    data -> data -> <your application name> -> databases -> <databasename>.db
  • Navigate to the above location using the following command. Remember that we are not going inside the .db file now:
    cd data/data/<your application name>/databases
  • Now, in order to query the database, we need to execute SQLite queries. To do this, we need to start off the SQLite3 module of the ADB. Execute the following command:
    sqlite3 <databasename>.db
  • If your command is syntactically correct you should see something like this
    SQLite version 3.5.0
    Enter “.help” for instructions
  • Each line should now start with “sqlite>”.
  • List tables : In order to list all the tables present in the database, use the following command
  • Now, you can execute raw SQLite queries just like you would in an SQLite RDBMS, in order to verify what data the tables in your database hold.
  • Try the below query by substituting NeroTable with the name of your table.
    select * from NeroTable
  • The above query should present you with all the rows and columns present in the table in a formatted fashion.

This post assumes that you have a fair knowledge of SQLite queries and hence I suggest you try some of those out so that you  can have a hands on practice of working with command line tools. It is quite apparent that this gives us a direct access to our databases and we do not have to resort to logs in order to view the data inside the tables as we were doing earlier. Also it prevents writing extra lines of code in our activity.
While developing complex applications containing multiple tables, ADB serves our purposes beautifully and is hence preferred.

Series Navigation<< Introducing Android Debug Bridge – Part INetwork Access in Android Applications >>

Leave a Reply

Your email address will not be published. Required fields are marked *


* Copy This Password *

* Type Or Paste Password Here *

41,055 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>