【发布时间】:2016-08-02 17:47:25
【问题描述】:
目前我有一个要求,我需要读取大量的插入查询,大约 100 000 个写在 .sql 文件中的查询。我需要从 SdCard 读取此文件并更新我的应用程序中的本地 sqlite 数据库。
我正在使用以下代码并成功更新:
同时我担心性能问题和应用程序挂起的风险,当它就像一个更重的 sql 文件的任务时。我需要改变我现在使用的方法吗? Sqlite 数据库是否有更好的实现来无风险地执行此任务。
/* Iterate through lines (assuming each insert has its own line
and theres no other stuff) */
while (insertReader.ready()) {
String insertStmt = insertReader.readLine();
db.execSQL(insertStmt);
bytesRead += insertStmt.length();
int percent = (int) (bytesRead * 100 / totalBytes);
// To show the updating data progress
if (previousPercent < percent) {
System.out.println(percent);
previousPercent = percent;
Bundle b = new Bundle();
b.putInt(AppConstants.KEY_PROGRESS_PERCENT, percent);
Message msg = new Message();
msg.setData(b);
errorViewhandler.sendMessage(msg);
}
result++;
}
insertReader.close();
【问题讨论】:
标签: java android database sqlite insert