【问题标题】:Inserting large amount of data into android sqlite database?将大量数据插入android sqlite数据库?
【发布时间】:2011-09-21 21:10:57
【问题描述】:

我有大量数据要导入到一个 sqlite 数据库中。 4 列和 150 行。目前数据在 Excel 电子表格中。

如何将其导入到我的 Android 应用程序中?

    String SQL = "create table " + TABLE + "( " 
        + BaseColumns._ID
        + " integer primary key, " 
        + Column1+ " text, "
        + Column2+ " text, "
        + Column3+ " text, " 
        + Column4+ " text);";
        db.execSQL(SQL);        

        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");
        db.insert(DBAdapter.TABLE, null, values);

        ContentValues values2 = new ContentValues();
        values2.put(DBAdapter.Column1,  "P");
        values2.put(DBAdapter.Column2,  "other");
        values2.put(DBAdapter.Column3,  "other");
        values2.put(DBAdapter.Column4,  "345");

} 

这就是我在数据库中插入两行的方式,但我不想为 150 行这样做?

【问题讨论】:

    标签: android database excel sqlite import


    【解决方案1】:

    您可以将信息存储在 CSV 文件中,然后读取文件并将每一行存储在 sqlite 中。

    【讨论】:

      【解决方案2】:

      您可以使用任何 db 控制台在桌面上加载数据库,将其添加到资源中并用您自己的文件替换 DbHelper 创建的 db 文件。 如果你使用 Motodev 会容易得多。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-06-03
        • 2018-07-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-28
        相关资源
        最近更新 更多