SQLite 簡單的資料庫

2021-07-14 16:50:46 字數 1135 閱讀 8604

1.建立資料庫和表

引數1.資料儲存的檔案位置

引數2.檔案建立工廠類,這裡不需要,寫為空

db=sqlitedatabase.openorcreatedatabase

("/data/data/com.coderqi.android2_lesson_04_database/database.db", null);

2.這裡進行建立表操作

2.1.拼接sql語句

string sql = "create table if not exists

student ('sid' integer primary key, 'name'

text, '***' text, 'age' integer);";

2.2.向資料庫物件傳送sql指令

db.execsql(sql);

3.新增資料

string sql = "insert into student (name,***,age)

values ('王五','男',21);";

db.execsql(sql);

4.刪除資料庫

string sql = "delete from student where sid = 1";

db.execsql(sql);

5.修改資料

string sql = 「update student set name = '張三'

where sid = 1」;

db.execsql(sql);

6.查詢資料

6.1.獲取資料庫使用的游標

cursor cursor =

db.query("student",null,null,null,null,null)

6.2 移動到第一行,如果返回為false,那麼證明沒有資料

if (cursor.movetofirst())while(cursor.movetonext());}

以下是**部分

SQLite資料庫簡單使用

二 建立資料庫 sqlite3 student.db 建立名為student的資料庫 sqlite3命令,引數就是資料庫的名稱,如果該資料庫已存在,則使用,如果不存在,則新建乙個 如圖 三 建立表 create table person id integer primary key autoincr...

SQLite簡單資料庫

通過觀察可以發現,不管是聊天列表還是 列表,有乙個共性 資料量大和資料結構複雜 那麼為什麼我們要用sqlite,有這麼幾個原因 sqlite常用的幾種資料型別為text文字型,integer整型,real浮點型,建 式要用規定的格式,如下 create table product 建立資料庫和資料表...

SQlite 資料庫的簡單操作

integer 整形值 real 浮點型 text 文字字串 blob 二進位制資料 比如檔案 ddl資料定義語句 建立 create table t class id integer primary key autoincrement,name text 如果不存在就建立 create table...