Aparna Shaji Peter
Aparna Shaji Peter

Reputation: 155

Insert values into SQLite database manually

I'm new to Android development and I've just started learning the basics of user-interface development. In my app, I have a spinner and I want to populate the spinner with values from the database. So, for taking values from the database, there have to be some values in it. How do I insert values to the database without writing a program? Can I insert it in any other way like how we insert values in MySQL and Oracle databases? Hope that my problem is well understood.

Upvotes: 9

Views: 9485

Answers (3)

Saf
Saf

Reputation: 227

If you want to inset the data manually(fully graphical) do the following:

  1. Go to the DDMS perspective
  2. File explorer (tab-menu)
  3. Locate your db (/data/data/com.example.your_package/databases/your_db.db)
  4. click on the icon up placed beside the other tabs (pull a file from the device)
  5. save your db on your computer
  6. open SQLite Database Browser [Download it from here][1] [1]: http://sourceforge.net/projects/sqlitebrowser/
  7. do your work, and save
  8. turn back to your DDMS and locate your db
  9. click on the icon up placed beside the other tabs (Push a file onto the device)
  10. locate your edited db and click open

Upvotes: 2

Ajay S
Ajay S

Reputation: 48592

Can I insert it in any other way like how we insert values in MySQL and Oracle databases? Hope that my problem is well understood.

Yes you can insert the data in SQLite database manually by following steps.

Steps to follow:

1) Go to your sdk-tool directory . (Example - E:\android-sdk-windows\tools>)
2) Type adb shell and press enter
3) cd data
4) cd data
5) cd your package name
6) cd databases

Once you reach here then do these steps to create database and create tables then insert data into it.

sqlite3 your_database_name.db;
SQLite version 3.7.7 2011-06-25 16:35:41

Enter ".help" for instructions Enter SQL statements terminated with a ";"

sqlite> CREATE TABLE province_table (pid INTEGER PRIMARY KEY AUTOINCREMENT, pname TEXT);
sqlite> INSERT INTO province_table (pname) values ('Quebec');
sqlite> ...
sqlite> .q

.q for quiet from SQLlite and now you have database your_database_name.db.

But here in your case if you want to create the database for all mobile such like that once your application run the start database manipulation then you must to do it programmatically.

Upvotes: 0

Deepak Bala
Deepak Bala

Reputation: 11185

You can use the sqllite3 tool from an adb shell to perform queries manually. I would not rely on it being present on production devices though (without rooting and going through a few painful steps). You can use the tool on the emulator.

adb -s emulator-5554 shell
# sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db
SQLite version 3.3.12

Upvotes: 0

Related Questions