I am working on an application on android where my current need is to pull data from web server and store it into db(sqlite db file) file which will be used further by the application to show the data to the user. I have little clue that I need to write a web service which will pull the data for me from the server, But I exactly don't know how to store it in SQLite db file.
Uptil now am able to get the data from the server in ArrayList<HashMap<String, String>>InfoList;
Now I want to store all the data of ArrayList<HashMap<String, String>>InfoList; => to sqLite database
which will be later used by application locally. How can this be done.
Request to all the experts to guide me. Thanks in advance.
Asked
Active
Viewed 3,820 times
0

Mayur
- 789
- 10
- 37
-
possible duplicate of [Android SQLite Example](http://stackoverflow.com/questions/12015731/android-sqlite-example) – Karolis.sh May 05 '14 at 11:38
-
@KarolisŠarapnickis: I am asking for data pull from web server and then storing it to SQLite. I can write code for SQLite, but I don't know how to handle that from Webserver to sqlite. – Mayur May 05 '14 at 11:40
2 Answers
0
you can do in this way,(xml parsing and storing in db)
SAXParserFactory saxPF = SAXParserFactory.newInstance();
SAXParser saxP = saxPF.newSAXParser();
XMLReader xmlR = saxP.getXMLReader();
URL url = new URL("your url"); // URL of the XML
XMLHandler myXMLHandler = new XMLHandler();
xmlR.setContentHandler(myXMLHandler);
xmlR.parse(new InputSource(url.openStream()));
data = XMLHandler.data;
db.execSQL("create table if not exists entries(subject_name varchar,subject_id varchar)");
for (int i = 0; i < data.getSubname().size(); i++) {
String subname=data.getSubname().get(i);
String subid=data.subid().get(i);
db.execSQL("insert or replace into entries values('"+subname+"','"+subid+"')");
}
}
For retrieving data we use cursor.
Edit: this question already has been solved, you can refer Insert JSON data into the SQLite database in android?

Community
- 1
- 1

Pandiri Deepak
- 176
- 3
- 15
0
I think you should use JSON as output format from your web service. Not xml, since it difficult to parse in js.
Once you have JSON in javascript, you could use sql.js https://github.com/kripken/sql.js It is a javascript api for SQLite. Use it to import your json into sqlite.

hoogw
- 4,982
- 1
- 37
- 33