My安卓知識1 SQLite資料庫

2021-08-03 03:49:56 字數 1058 閱讀 5735

2023年五月份到六月份做了乙個小專案,關於android的,想記錄一下學到的一些知識,做成乙個小系列吧,算是對自己這乙個多月來的見證。首先說明,這些知識也都是從網上各處學習來的,我自己做了一些小整理。

1.sqlite資料庫

之前用的資料庫是mysql和sqlserver,還用過oracle,雖然不是很精通,這次第一次接觸sqlite,感覺用起來很方便,直接在android專案裡寫乙個dbhelper類來繼承sqliteopenhelper就行。但是有些功能還是有侷限性,在定義資料型別的時候,string就不對,而text就對,還有無法寫double等型別,雖然說會自動轉換,個人感覺還是會有些不方便。

public class dbhelper extends sqliteopenhelper

public static dbhelper getdbhelper(context context)

return dbhelper;

}@override

public void oncreate(sqlitedatabase db)

@override

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

}這是我專案裡的**,很簡單,只是建了乙個名為car的資料庫,還有user、car、fuel三個表,並插入資料。在sqlite中實現增刪改查也很簡單,這是另乙個類裡實現的方法。

//查詢使用者名稱和密碼

public boolean login(string id,string password));

if(cursor.movetofirst()==true)

return false;

}//註冊用(增加操作)

public boolean register(user user,string _id));

if(cursor.movetofirst()!=true);

sdb.execsql(sql,obj);

return true;

}else

歡迎各位程式猿&程式媛批評指正~

iOS資料持久化1 SQLite

這裡採用乙個二次封裝的例項來初步演示和實現 更新 如果嫌麻煩,這裡放乙個,建議github 你將有這幾個檔案 其中data.db是database檔案 讓後組織進 project 最好放在最外面,使用時就不必新增子目錄 修改 building settings swift compiler gene...

安卓建立SQLite資料庫

新建乙個myopenhelper類,繼承sqliteopenhelper,實現它的構造方法和oncreate,onupgrade方法,構造方法myopenhelper有四個引數 1 context 上下文環境 2 name 資料庫的名字 3 factory 目的建立cursor 物件 4 versi...

安卓中的SQLite資料庫的基本操作1

布局檔案 邏輯 檔案 package com.example.day14 sqlite import com.example.day14 sqlite.utils.mysqlite import android.database.cursor import android.database.sqli...