Android下SQLite数据库一条条地插入记录太慢了,1000条记录要30来秒时间,如何改进

Android下SQLite数据库一条条地插入记录太慢了,1000条记录要30来秒时间,怎么改进?
Android下SQLite数据库一条条地插入记录太慢了,1000条记录要30来秒时间,怎么改进?

------解决方案--------------------
帮顶,好些也是和2L说的那样吧,插入多条记录时执行一个事务处理。
java中是执行数据库操作应该可以执行事务操作的。
------解决方案--------------------
使用SQLite提供的事务方式操作数据库。使用事务机制时,1000条记录只有1个I/O操作,不使用事务机制时是1000个I/O操作,一个IO操作算25毫秒的话,那么1000个I/O操作就是25秒了。所以1000条记录使用事务操作比不使用事务操作省了25秒
------解决方案--------------------
Actually, SQLite will easily do 50,000 or more INSERT statements per second on an average desktop computer. But it will only do a few dozen transactions per second. Transaction speed is limited by the rotational speed of your disk drive. A transaction normally requires two complete rotations of the disk platter, which on a 7200RPM disk drive limits you to about 60 transactions per second. 

By default, each INSERT statement is its own transaction. But if you surround multiple INSERT statements with BEGIN...COMMIT then all the inserts are grouped into a single transaction. The time needed to commit the transaction is amortized over all the enclosed insert statements and so the time per insert statement is greatly reduced. 


------解决方案--------------------
轻量级哦~轻量哦,不适合大量数据存储和读取的~

单机系统?为何不在后台处理?
------解决方案--------------------
确实,android中做一些sql的循环操作,需要加上事务的处理。不然效率太差了
------解决方案--------------------
想提高效率,自定义格式,别用sqlite啊,文件系统级别还是很快的,如果感觉慢,可以上mmap用内存文件,效果打打滴
------解决方案--------------------
用事务来处理
.beginTransaction();
cmd.exec();
.Commit();
------解决方案--------------------
我也刚刚解决了这个问题,很不错,!1

C/C++ code
sqlite,sqlite3_exec执行事务批量更新记录
2009-02-04 17:19
sqlite3 *db;
sqlite3_open(theApp.getDB_fullPath(), &db);

  
sqlite3_exec(db,"BEGIN TRANSACTION",0,0,0);
sqlite3_exec(db,"update tabConfFeichengRen set value="+yingEr+" where type='yingEr'",0,0,0);
sqlite3_exec(db,"update tabConfFeichengRen set value="+erTong+" where type='erTong'",0,0,0);
sqlite3_exec(db,"update tabConfFeichengRen set value="+erTongJiaChuang+" where type='erTongJiaChuang'",0,0,0);
int rc=sqlite3_exec(db,"COMMIT",0,0,0);

if(rc!=SQLITE_OK)
{
    AfxMessageBox("出错!");
}
else
{
    AfxMessageBox("OK!");
}


sqlite3_close(db);