Android學習之SQLite資料庫儲存

2021-08-18 17:55:37 字數 1057 閱讀 1863

今天學習sqlite資料庫儲存,sqlite資料庫是輕量級的,非常小,只有幾百k大小,非常

移動裝置使用,幾乎所有的手機使用的都是sqlite資料庫。

sqlite儲存的資料型別:.db

資料儲存的路徑:/data/data/packagename/databases/***.db

然後是最重要的api的學習:sqliteopenhelper,是乙個抽象類

public sqliteopenhelper(context context, string name, curso***ctory factory, int version):構造方法

abstract void oncreate(sqlitedatabase db):用於建立表

abstract void onupgrade():用於版本更新

sqlitedatebase getreadabledatebase():得到資料庫連線

sqlitedatebase:代表與資料庫的連線的類

方法:long insert():用於執行insert sql,返回id值

int update():用於執行 updata sql

int delete():用於執行 delete sql

cursor query():用於執行select sql ,返回包含查詢結果資料的cursor

void execsql(sql):執行sql語句

begintransaction():開啟事務

sertransactionsuccessful():設定事務是成功的

endtransaction():結束事務,可能提交事務或回滾事務

opendatabase(string path, curso***ctory factory, int flags):得到資料庫連線

cursor:包含所有查詢結果記錄的結果集物件(游標,游標)

int getcount():匹配的總記錄數

*** get***(columnindex):根據字段下標得到對應的值

int getcolumnindex(columnindex):根據欄位名得到對應的下標

Android資料儲存和訪問之SQLite儲存

sqlite資料庫簡介 acid 資料庫事物正確執行的4個基本要素 1 原子性2 一致性3 隔離性4 永續性 資料的常用操作主要有以下 1 建立資料庫 2 新增資料庫 public void adddata view view 3 刪除資料 public void deletedata view v...

android中使用adb檢視sqlite資料庫

1.進入到控制台中,輸入adb shell,進入到命令模式的環境中 2.輸入cd data data 轉換到專案資料夾 3.選擇的專案檔案,比如我的com.android.homework,輸入命令 cd com.android.homework 4.可以使用ls l 命令檢視當前目錄中的檔案 5....

Android中sqlit資料庫公升級或者降級

sqlite是android內建的乙個很小的關係型資料庫。sqliteopenhelper是乙個用來輔助管理資料庫建立和版本公升級問題的抽象類。我們可以繼承這個抽象類,實現它的一些方法來對資料庫進行自定義操作。下面兩個方法必須重寫 onupgrade 呼叫時機是使用者在做應用更新,覆蓋安裝後啟動,如...