Working with SQLite databases through command Line in android.

By | January 23, 2012

Hello all,
In todays tutorial I will show you how to work with sqlite databases in android through command line.

Advantages
1. You can browse any number of databases.
2. You can write any queries and execute.

First go through these tutorials to get a glance of how to work with sqlite databases in android.
1. http://coderzheaven.com/2011/04/sqlitemanager-plugin-for-eclipse/
2. http://coderzheaven.com/2011/04/using-sqlite-in-android-a-really-simple-example/
3. http://coderzheaven.com/2011/02/working-with-sqlite-database-in-android/

After going through these tutorials you will get to know these.
1. How to create an SQLite database.?
2. Where to locate the database file in your device or emulator?
3. How to browse the database using the plugin I provided in this example(http://coderzheaven.com/2011/04/sqlitemanager-plugin-for-eclipse/
)?

I am using the sqlite database that I created using this example
http://coderzheaven.com/2012/01/how-to-save-score-in-android-cocos2d/

Now open the command prompt or terminal and type

adb -s emulator-5554 shell

now type the path of your sqlite database like this.

sqlite3 /data/data/com.coderzheaven.pack/databases/mytest.db

check the screenshot for example

Now look at the screenshot for how am I navigating through the tables and selecting and inserting values to the table creating new tables etc.
Click and enlarge the image to see it.


You can exit the shell by typing ā€˜ ctrl+dā€™ twice.

This is the path of my database file
/data/data/com.coderzheaven.pack/databases/mytest.db

Which you can see by opening the file explorer from the window menu and expanding your package folder.(check this example for a screenshot of how to see the database http://coderzheaven.com/2012/01/how-to-save-score-in-android-cocos2d/)

Now about the SQLite database file.
Here I have three tables my_table, temp_table and test_table.
I am executing different commands to manipulate these tables.
The results are appearing just after the command

Please leave your valuable comments on this post.
Also +1 this post to share it to others if you liked it.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Reply

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