一般使用sqliteopenhelper 子類運算元據庫
繼承sqliteopenhelper 類實現兩個方法,至少乙個構造方法
oncreate(sqlitedatabase db) 在這個方法實現具體的資料庫建立
onupgrade(sqlitedatabase db, int oldversion, int newversion)
資料庫公升級具體實現 這兩個方法會在資料庫建立公升級是自動呼叫
(資料名在構造方法中傳入)使用oncrate 建立資料庫表
getwritabledatabase getreadtabledatabase 方法會返回乙個資料庫public
void
oncreate(sqlitedatabase db)
例項 兩個方法又都會呼叫同乙個方法 getdatabaselocked 方法找到
這個資料庫建立或開啟
使用反回sqlitedatabase例項進行操作sqlitedatabase db;
public
void
connection()
public
void
insert(contentvalues values)
public
void
query();
cursor curse = db.rawquery(sql, selectionargs);
closeconnection();
}public
void
delect();
db.delete("book", "id=?", whereargs);
closeconnection();
}
資料庫操作 SQLite
sqlite 是乙個輕量級的關聯式資料庫。sqlite最初的設計目標是用於嵌入式系統,它占用資源非常少,在嵌入式裝置中,只需要幾百k的記憶體就夠了,目前應用於android ios windows phone等智慧型手機。ios 使用時sqlite,只需要加入 libsqlite3.dylib 依賴...
資料庫操作 SQLite
sqlite 是乙個輕量級的關聯式資料庫。sqlite最初的設計目標是用於嵌入式系統,它占用資源非常少,在嵌入式裝置中,只需要幾百k的記憶體就夠了,目前應用於android ios windows phone等智慧型手機。ios 使用時sqlite,只需要加入 libsqlite3.dylib 依賴...
SQLite資料庫操作
建立資料庫需要使用的api sqliteopenhelper 必須定義乙個構造方法 arg1 資料庫的名字 people.db arg2 游標工廠 通常直接傳人null,則系統會使用預設的工廠 arg3 資料庫版本號 從1開始 方便公升級使用,不斷設定更大的值會呼叫,onupgrade方法 publ...