安卓之sqlite的簡單應用

2021-10-12 15:57:45 字數 1625 閱讀 5007

sqlite是乙個輕量型的資料庫,androidsdk自帶的,說白了,就是你手機裡面有乙個資料庫,但是你看不到,必須root之後才可看到,就這麼簡單。

db.execsql( "create table if not exists aofax(_id integer primary key autoincrement,aofaxname varchar,aofaxpassword varchar,username varchar,password varchar,domain varchar)");

package org.jinheng;

import android.content.context;

import android.database.databaseerrorhandler;

import android.database.sqlite.sqlitedatabase;

import android.database.sqlite.sqliteopenhelper;

public class sqlite extends sqliteopenhelper }}

return instance;

}// 構造方法不對外暴露

private sqlite(

context context, string name, sqlitedatabase.curso***ctory factory, int version)

// 構造方法不對外暴露

private sqlite(

context context,

string name,

sqlitedatabase.curso***ctory factory,

int version,

databaseerrorhandler errorhandler)

// 初始化操作,會執行oncreate

@override

public void oncreate(sqlitedatabase db)

// 用於公升級資料庫,當version 變動了,就會呼叫onupgrade方法

@override

public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {}

}

呼叫:呼叫需要使用到sqlitedatabase物件操作

// 沒有資料庫就建立,有就開啟 

sqlite sqliteopenhelper = sqlite.getinstance(genericconnectionassistantactivity.this);

sqlitedatabase database = sqliteopenhelper.getwritabledatabase();

database.execsql("delete from aofax");

database.execsql("insert into aofax(aofaxname,aofaxpassword,username,password,domain)

values ('123','456','789','852','963')");

安卓中SQLite的簡單使用

sqliteopenhelper 是安卓中建立資料庫的乙個幫助類,至少實現其中的oncreate和onupgrade方法。sqliteopenhelper 的方法 方法作用 oncreate sqlitedatabase db 建立資料庫時呼叫 onupgrade sqlitedatabase db...

安卓Sqlite的使用

安卓儲存資料之一資料庫的使用 做安卓專案肯定都會用到資料庫儲存資料的,安卓也給我們提供了乙個sqlite資料庫以及運算元據庫的類sqliteopenhelper。我們就可以輕鬆得對自己的資料進行增刪改查了。下面上資料庫操作類的 ublic class mysqliteopenhelper exten...

安卓中的儲存(SQLite)

sqlite 底層實現c和c 語言,本身是開源軟體版。主要應用在儲存聯絡人 儲存簡訊 備忘錄和手機上的音訊檔案等。優點是 資料安全性比較高,資料也方便管理。相應的api sqlitedatabase 開啟或者關閉資料庫 sqliteopenhelper 工具類 cursor物件 cursoradap...