Sqlite   发布时间:2022-05-22  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了sqlite插入速度优化方案 申请加精大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
本帖最后由 yxmshaka 于 2013-4-10 17:52 编辑

我们创建测试的表是user,@R_489_4631@,name,age,height,REMARK测试用的小米2,默认条数为100行。
?
代码片段,双击复制
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//MysqliteOpenHelper作为一个访问sqlite的帮助类,提供两方面的功能
//1.getReadableDatabase(),getWritableDatabase()可以获sqliteDatatbase对象,
//对这个对象进行相关操作
//2.提供了onCreate()和onUpgrade()两个回调函数,允许我们在创建和升级数据库时进行操作
public class MysqliteOpenHelper extends sqliteOpenHelper {
static final String DATABASE_name = "meacs.db" ;
String TAG = "MysqliteOpenHelper" ;
public MysqliteOpenHelper(Context context) {
this (context,DATABASE_name, null , 1 );
}
MysqliteOpenHelper(Context context,85)!important">int version) {
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-family:Consolas,version);
}
// 必须要有这一个构造方法
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-family:Consolas,String name,
@H_623_197@ cursorFactory factory,monospace!important; min-height:auto!important"> version) {
super :1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-family:Consolas,factory,version);
// Todo auto-generated constructor stub
}
// 当数据库第一次创建的时候被调用,
// 当调用getReadableDatabase ()或getWritableDatabase 的时候
@OverrIDe
voID onCreate(sqliteDatabase db) {
// Todo auto-generated method stub
Log.d(tag, "onCreate" );
String sql = "create table user(ID INTEGER PRIMary key autoincrement,"
+ "name varchar(20)," + "age integer,255)!important">"height long,"
"REMARK varchar(12))" ;
db.execsql(sql);
@H_874_270@ }
close() {
sqliteDatabase db = .getWritableDatabase();
db.execsql( "drop table user" );
}
@OverrIDe
onUpgrade(sqliteDatabase db,monospace!important; min-height:auto!important"> oldVersion,monospace!important; min-height:auto!important"> newVersion) {
// Todo auto-generated method stub
"onUpgrade" );
}
}

1。使用COntentValues插入。完成时间:4805493666(纳秒)
23
/**
* ContentValues方式
*
* @param sum
* @return
*/
long insert1( sum) {
long before = System.nanoTime();
@H_443_126@mysqliteOpenHelper dbHelper = new MysqliteOpenHelper(MainActivity. );
// 得到数据库对象
sqliteDatabase db = dbHelper.getWritableDatabase();
for ( i = 0 ; i < sum; i++) {
ContentValues cv = ContentValues();
cv.put( "name" "zhangsan" );
"age" "23" );
@H_623_197@ "height" 1.78 );
"REMARK" "无" );
db.insert( "user" :1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-family:Consolas,cv);
}
db.close();
after = System.nanoTime();
return after - before;
}

2。使用基本slq语句插入。完成时间:3734808485(纳秒)
13
insert2( sum) {
before = System.nanoTime();
);
// 得到数据库对象
sqliteDatabase db = dbHelper.getWritableDatabase();
; i < sum; i++) {
"insert into user(name,REMARK) values('zhangsan',23,1.78,'无')" ;
db.execsql(sql);
}
db.close();
after = System.nanoTime();
after - before;
}

3。使用sqlliteStatement插入。完成时间:4754616203(纳秒)
19
insert3( sqliteDatabase db = dbHelper.getWritableDatabase();
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-family:Consolas,REMARK) values(?,?,?)" ;
sqliteStatement stmt = db.compileStatement(sql);
; i < sum; i++) {
stmt.clearBindings();
stmt.bindString( );
stmt.bindLong( 2 23 );
3 178 );
4 );
stmt.execute();
}
@H_623_197@ db.close();
after = System.nanoTime();
after - before;
}

4。使用一次插入多条的方式。完成时间:245414315(纳秒)
22
insert4( ; i < sum / 10 ; i++) {
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-family:Consolas,'无'),"
"('zhangsan',"
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-family:Consolas,"
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-family:Consolas,"
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-family:Consolas,"
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-family:Consolas,"
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-family:Consolas,"
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-family:Consolas,"
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-family:Consolas,"
@H_623_197@ ;
db.execsql(sql);
}
db.close();
after = System.nanoTime();
after - before;
}

5.使用事务处理插入方式。完成时间:229787881(纳秒)
16
insert5( db.begintransaction();
; i < sum; i++) {
;
db.execsql(sql);
}
db.settransactionsuccessful();
db.endtransaction();
db.close();
after = System.nanoTime();
after - before;
@H_623_197@ }


最近在忙cocos2d-x开发的事情,睡得比较晚,临睡前 看到了一篇文章 感觉很好 ,跟大家分享了,这个绝对是精华所在。
刚才有人说转帖要说明出处又回去找了一遍找到了做人要厚道 哈
转自:http://blog.csdn.net/ihrthk/article/details/8741047

回帖推荐

laozhao查看楼层

实际测试当同时使用事务时,循环内部使用COntentValues更快 ContentValues: 342224121 270477293 488250732 623504637 164733888 149871825 158111570 ------ sql: 210998534 743438721 241638183 187103272 172088624

yxmshaka查看楼层

ContentValues快 这个是必然的 但老程序员对t-sql都有情怀的
本图文内容来源于网友网络收集整理提供,作为学习参使用,版权属于原作者。
  • 上一篇:用触发器实现sqlite的外键约束下一篇:【原创】sqlite学习笔记

sqlite相关文章

sqlite 3.33.0 发布,新特性了解一下?
sqlite 开发团队于 2020 年 8 月 14 日发布了 sqlite Release 3.33.0 版本,本文给大家分析了这个版本中的一些新特性。包括支持 updatE FROM 语句、数据库文件最大支持 281 TB、PRAGMA integrity_check 语句增强、decimal 插件、ieee754 插件增强、命令行工具增强、查询计划改进以及WAL 索引文件恢复。
sqlite学习笔记
安装 在Windows上安装sqlite。 访问官网下载下Precompliled Binaries for Windows的两个压缩包。 创建sqlite文件夹,路径不要包含中文,把压缩包的内容解压
【Android数据存储】sqlite使用实例(附源码)
实例: 会员信息管理 功能:1.查看数据库 2.清空数据库 3.增加会员 4.删除会员 5.更新会员 6.查找会员   数据库基类 – DBHelper.java 01 package com.wirelessqa.sqlite; 02   03 import android.content.Context; 04 import android.database.sqlite.sqliteData
sqlite数据库管理
关于SQLite SQLite是一个轻量的、跨平台的、开源的数据库引擎,它的在读写效率、消耗总量、延迟时间和整体简单性上具有的优越性,使其成为移动平台数据库的最佳解决方案(如iOS、Android)。 然而免费版的sqlite有一个致命缺点:不支持加密。这就导致存储在Sqlite中的数据可以被任何人用任何文本编辑器查看到。比如国内某团购iOS客户端的DB缓存数据就一览无余: sqlite加密方式
关于SQLite SQLite是一个轻量的、跨平台的、开源的数据库引擎,它的在读写效率、消耗总量、延迟时间和整体简单性上具有的优越性,使其成为移动平台数据库的最佳解决方案(如iOS、Android)。 然而免费版的sqlite有一个致命缺点:不支持加密。这就导致存储在Sqlite中的数据可以被任何人用任何文本编辑器查看到。比如国内某团购iOS客户端的DB缓存数据就一览无余: sqlite加密方式
sqlite这么娇小可爱,不多了解点都不行啊
在我眼里,MySQL和Oracle是这样的sqlite在是这样的 所以这么萌的数据库,我真的应该多了解她的。 简介 SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统。它的设计目标是嵌入式的,目前Android和iOS的设备内置的都是sqlite数据库。sqlite然娇小,但也支持事务和多数的SQL92标准。 主要特点 zero-configuration 无需安装和管理
sqlite 这么娇小可爱,不多了解点都不行啊
(点击上方蓝字,快速关注我们) 作者:空之境界 网址:http://supermao.cn/sqlitezhe-yao-jiao-xiao-ke-ai-bu-duo-liao-jie-dian-du-bu-xing-a/ 在我眼里,MySQL和Oracle是这样的sqlite在是这样的 所以这么萌的数据库,我真的应该多了解她的。 简介 SQLite,是一款轻型的数据库,是遵守ACID的关系型数
@H_451_906@mySQLMsSQLOraclesqlitePostgre SQLR_639_11845@ariadbMongoDBNoSQLHBaseJDBCmycat
  • sqlite 3.33.0 发布,新特性了
  • sqlite学习笔记
  • • windows上如何安装sqlite
  • • 【Android数据存储】sqlite使用
  • sqlite数据库管理
  • sqlite3常用命令
  • • 加密你的sqlite
  • • 加密你的sqlite
  • sqlite这么娇小可爱,不多了解
  • sqlite这么娇小可爱,不多了解
  • sqlite 这么娇小可爱,不多了解
  • sqlitE3 使用总结

sqlite插入速度优化方案 申请加精

微信公众号搜 "程序精选"关注
  • sqlite 3.33.0 发布,新特性了
  • sqlite学习笔记
  • • windows上如何安装sqlite
  • • 如何在MVVMCross中使用社区SQL
  • sqlite – 评估与Dropbox同步核
  • • 如何理解sqlite`EXPLAIN QUERY
  • • 更新查询sqlite – Android
  • • “BEGIN..COMMIT;”在Sqlite中
  • sqlite选择哪里…和vs. case …
  • sqlite,在我的表中插入变量(c#
python-3.xpandasswiftarraysspring-boosql-serverdataframerubyamazon-webfirebasegoazurealgorithmVBAdelphiregexasp.net-coPowerSHellelasticsearuby-on-raspring-mvcloopsgoogle-clomultithreavisual-stuapache-spaperfoRMANctomcatasp.net-mvgoogle-clo.net-coreunity3dTSQLfor-loopvb.netmavenmachine-leauthenticascalaherokudjango-modpysparkif-statemelinqdplyrobjective-asynchronosshwinformsjpasecurityentity-frauser-intergraphqlfirebase-rdjango-vieoptimizatidebuggingmatlabvariablesgoogle-bigxamarinamazon-ec2parsingrecursionnetworkingentity-fraintellij-iimage-proccmakefirebase-asqlalchemyautomationindexingdata-strucIntegersql-servernlpspring-datapache-spa

大佬总结

以上是大佬教程为你收集整理的sqlite插入速度优化方案 申请加精全部内容,希望文章能够帮你解决sqlite插入速度优化方案 申请加精所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:ageheightname
猜你在找的Sqlite相关文章
其他相关热搜词更多
phpJavaPython程序员load如何string使用参数jquery开发安装listlinuxiosandroid工具javascriptcap