Using Rest to Store Data in Sqlite

I am creating my first Android application that will use SQlite. I have zero experience working with databases, except creating a mysql database for use with wordpress ...


Editing: after some research on rest, I'm still confused about how each other is suitable for rest, sqlite and android dev. My goal is to access the leisure-based web service through a URL and access some datasets and then store them in my SQlite database. Then I want to access the contents of the database through my java program and use them accordingly.

Datasets can be downloaded individually in CSV format , but since I will use so many of them, I don’t want to go through each line individually and store them in a database. I hope that there will be a more efficient way to store these datasets in a database.

My main questions are:

  • How to copy XML content of webpage from url to sqlite database? Can I do this using my java program via sqlite database or java library?
  • Do I only need to copy the contents of the web pages from the url to the sqlite database once? If so, what can I do if any information is changed in the data sets?
+7
source share
3 answers

First you need a schema for your sqllite DB. This schema should map to objects behind the web service. For example, you need a Person table in your database if there is a Person object on the Internet. It depends on what you want to capture.

When you finish designing the schema, you should start writing code that helps you create and manage the database on Android. This is done using the SQLiteOpenHelper class: http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html

If you need to keep DB synchronization with data in the cloud (web services), you should synchronize. Android provides a very efficient synchronization structure.

Also, watch this video from Android engineers explaining best practices: http://www.youtube.com/watch?v=xHXn3Kg2IQE

Note that to actually retrieve data from the web service, you would use the UrlConnection API: http://developer.android.com/reference/java/net/URLConnection.html

This pattern probably captures much of it. http://developer.android.com/resources/samples/SampleSyncAdapter/index.html

+5
source

Regarding reading CSV files, there are some good resources here:

Can you recommend a Java library for reading (and possibly writing) CSV files?

Once you read each line of the CSV into an object, you can expand and save it in the database. I am the author of ORMLite , so I’ll talk about usage. I do not believe that there is a sleeping port for Android.

There are several Android examples to help you speed up your work with ORMLite. Also some good tutorials . If you want to write multiple lines at once, I would recommend using the ORMLite function of batch tasks. See the discussion of creating object lists on the mailing list for information.

+3
source

I can answer your first question: "I'm not sure how to add them efficiently"? Yes, SQlite is very powerful and intelligent, you can add a thousand records in one transaction, just like a traditional database. This greatly improves performance.

about the second question, as in my understanding, because the CVS file is very simple, so you can download and analyze it yourself.

0
source

All Articles