9

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.

3
  • are we talking about a sqlite-db in memory of the phone or some sqlite-db on a seperate server? Commented Apr 10, 2013 at 15:43
  • sqlite-db in phone memory Commented Apr 10, 2013 at 15:44
  • check google for a SQLiteOpenHelper. thats the class you need to have to handle all the traffic with the database in memory. and don't worry, it takes some time to rewrite examples until they do what they need to do for you Commented Apr 10, 2013 at 15:49

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

So I've to insert values to the DB via a program?
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.