Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

To insert large amount of data in android SQLite Database

I am new in Android Development.

Currently, working with SQLite Database in Android.

My problem is that I have a large amount of data which I have to store in SQLite Database in Android.

There are 2 tables: One having 14927 rows and the other one has 9903 rows.

Currently the database in sql. And I have copy these data in excel sheet but don't understand how can I import these data in SQLite Database.

I go through the following link:

Inserting large amount of data into android sqlite database?

Here, the solution is posted regarding CSV File. But want to know other ways of doing this.

Please let me know what is the best way to import such a large data in Android.

Please help me. Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Do Like This

SQLiteDatabase sd;
    sd.beginTransaction();


        for (int i = 0; i < data.size(); i++) {
            ContentValues values = new ContentValues();
            values.put(DBAdapter.Column1,  "HP");
            values.put(DBAdapter.Column2,  "qw");
            values.put(DBAdapter.Column3,  "5280");
            values.put(DBAdapter.Column4,  "345, 546");
            sd.insert(DBAdapter.TABLE, null, values);
            sd.insertWithOnConflict(tableName, null, values, SQLiteDatabase.CONFLICT_IGNORE);

        }

    sd.setTransactionSuccessful();
    sd.endTransaction();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...