成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Android批量插入數(shù)據(jù)

移動開發(fā) Android
本文通過全方位的介紹和講解為讀者朋友們呈現(xiàn)出了Android批量插入數(shù)據(jù)的實現(xiàn)方法,解決了以往的上萬次插入操作速度慢的問題,大大提高了插入速度。

Android中在sqlite插入數(shù)據(jù)的時候默認一條語句就是一個事務(All individual SQL Statements, (with rare exceptions like Bulk Inserts with No Log, or Truncate Table) are automaticaly "In a Transaction" whether you explicitly say so or not.. (even if they insert, update, or delete millions of rows).),因此如果存在上萬條數(shù)據(jù)插入的話,那就需要執(zhí)行上萬次插入操作,操作速度可想而知。因此在Android中插入數(shù)據(jù)時,使用批量插入的方式可以大大提高插入速度。

批量插入的模板如下:

  1. public void inertOrUpdateDateBatch(List<String> sqls) {   
  2.         SQLiteDatabase db = getWritableDatabase();   
  3.         db.beginTransaction();   
  4.         try {   
  5.             for (String sql : sqls) {   
  6.                 db.execSQL(sql);   
  7.             }   
  8.             // 設(shè)置事務標志為成功,當結(jié)束事務時就會提交事務   
  9.             db.setTransactionSuccessful();   
  10.         } catch (Exception e) {   
  11.             e.printStackTrace();   
  12.         } finally {   
  13.             // 結(jié)束事務   
  14.             db.endTransaction();   
  15.             db.close();   
  16.         }   
  17.     } 

注意此處的:

  1. db.execSQL(sql);   

官方的API顯示:

public void execSQL (String sql)

Added in API level 1

Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.

It has no means to return any data (such as the number of affected rows). Instead, you're encouraged to use insert(String, String, ContentValues)update(String, ContentValues, String, String[]), et al, when possible.

When using enableWriteAheadLogging(), journal_mode is automatically managed by this class. So, do not set journal_mode using "PRAGMA journal_mode'" statement if your app is using enableWriteAheadLogging()

Parameters
sql the SQL statement to be executed. Multiple statements separated by semicolons are not supported.
Throws
SQLException if the SQL string is invalid

說明,每次執(zhí)行SQL只能有一條語句。在執(zhí)行的時候,不能寫成:

  1. insert into student values('yang','boy');insert into student values('zhou','girl');   

形式,而需要將兩條SQL語句拆開,每條SQL語句執(zhí)行一次。

責任編輯:閆佳明 來源: csdn
相關(guān)推薦

2021-04-08 10:55:53

MySQL數(shù)據(jù)庫代碼

2011-08-04 18:00:47

SQLite數(shù)據(jù)庫批量數(shù)據(jù)

2021-09-27 07:56:41

MyBatis Plu數(shù)據(jù)庫批量插入

2021-02-01 00:04:13

Dictionary數(shù)據(jù)批量

2024-10-22 08:47:03

2010-09-03 11:47:38

SQL刪除

2010-09-01 16:26:11

SQL刪除批量

2022-09-29 10:06:56

SQLMySQL服務端

2023-12-30 20:04:51

MyBatis框架數(shù)據(jù)

2010-09-08 16:53:43

SQL查詢循環(huán)

2021-10-09 06:59:36

技術(shù)MyBatis數(shù)據(jù)

2025-04-07 03:00:00

SpringBoot數(shù)據(jù)庫

2009-07-20 17:03:55

批量插入數(shù)據(jù)ASP.NET

2013-09-22 10:25:23

MySQLSQL性能優(yōu)化

2020-11-23 10:50:27

MySQLSQL數(shù)據(jù)庫

2022-09-23 09:44:17

MyBatisforeach

2018-08-09 08:59:56

數(shù)據(jù)庫MySQL性能優(yōu)化

2021-09-14 13:15:43

MySQL數(shù)據(jù)庫腳本

2021-06-28 10:25:47

MySQL數(shù)據(jù)庫重復數(shù)據(jù)

2021-11-02 14:46:50

數(shù)據(jù)
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 免费av手机在线观看 | 一区二区三区免费 | 在线一区 | 久久激情网 | 久草精品视频 | 黄色免费网址大全 | 一级二级三级在线观看 | 午夜精品久久久久久久久久久久久 | 美女久久 | 激情免费视频 | 蜜桃官网| 狠狠干av| 99免费精品视频 | 全免一级毛片 | 在线中文字幕视频 | 国产羞羞视频在线观看 | 亚洲一区二区在线播放 | 日韩视频在线观看一区二区 | 精品国产免费一区二区三区演员表 | 古典武侠第一页久久777 | 91黄在线观看 | 亚洲欧美aⅴ | 亚洲一二三区免费 | 在线一区二区三区 | h视频免费观看 | 国产自产c区 | 91免费观看 | 欲色av | 国产色爽 | 国产精品国产成人国产三级 | 日韩欧美在线视频 | 国产一区 在线视频 | 精品免费国产一区二区三区四区 | 精精国产xxxx视频在线野外 | 欧美日韩精品一区二区三区四区 | 国产在线观看一区 | 国产无套一区二区三区久久 | 日韩在线观看网站 | 欧美日韩精品一区二区三区四区 | 精品久久久久久 | 精品日韩欧美一区二区 |