Hein du Plessis
Hein du Plessis

Reputation: 3357

Android: Loading data from a URL to SQLite

What's the easiest way to populate a SQLLite table with data off a URL?

I'm writing a Delphi web app that will generate a file on a server for my Android app to download.

In Delphi, I'll probably save it as a .csv file and use bulk import to import into MS SQL Server.

What's the easiest / best practice way to do this in Android? How would I download the file from the URL and then load it into SQLLite?

Many thanks for any pointers.

Upvotes: 0

Views: 1340

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007296

How would I download the file from the URL

Use HttpClient, as Frayser indicates.

and then load it into SQLLite?

You neglected to tell us what format you will use for the download.

If the format is the CSV you mentioned for other uses, parse it and use SQL INSERT statements (execSQL() or insert() with your SQLiteDatabase object). Wrap the INSERT statements in a transaction to improve performance, since each transaction requires a flash write, and flash writes are slow.

If you are downloading a complete SQLite database, just put it in getDatabasePath(), and open it when needed.

Upvotes: 1

Related Questions