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.
-
are we talking about a sqlite-db in memory of the phone or some sqlite-db on a seperate server?bofredo– bofredo2013-04-10 15:43:17 +00:00Commented Apr 10, 2013 at 15:43
-
sqlite-db in phone memoryAparna Shaji Peter– Aparna Shaji Peter2013-04-10 15:44:32 +00:00Commented 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 youbofredo– bofredo2013-04-10 15:49:00 +00:00Commented Apr 10, 2013 at 15:49
3 Answers
If you want to inset the data manually(fully graphical) do the following:
- Go to the DDMS perspective
- File explorer (tab-menu)
- Locate your db (/data/data/com.example.your_package/databases/your_db.db)
- click on the icon up placed beside the other tabs (pull a file from the device)
- save your db on your computer
- open SQLite Database Browser [Download it from here][1] [1]: http://sourceforge.net/projects/sqlitebrowser/
- do your work, and save
- turn back to your DDMS and locate your db
- click on the icon up placed beside the other tabs (Push a file onto the device)
- locate your edited db and click open
Comments
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
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