安卓儲存資料之一資料庫的使用
做安卓專案肯定都會用到資料庫儲存資料的,安卓也給我們提供了乙個sqlite資料庫以及運算元據庫的類sqliteopenhelper。
我們就可以輕鬆得對自己的資料進行增刪改查了。
下面上資料庫操作類的**:
ublic class mysqliteopenhelper extends sqliteopenhelper
@override
public void oncreate(sqlitedatabase db)
//資料庫更新的時候呼叫 int version發生改變的時候呼叫此方法
@override
public void onupgrade(sqlitedatabase db, int oldversion, int newversion) }}
以上就是sqliteopenhelper的使用,注釋都已經寫清楚 了,就不做解釋
下面就是我們要進行增刪改查的**:
ublic class mainactivity extends activity implements onclicklistener
private void initview()
@override
public void onclick(view v)
}//新增資料
private void add() );
toast.maketext(this, "新增成功", toast.length_short).show();
system.out.println("新增成功");
database.close();
}//刪除資料
private void delete()
//改動資料
private void change() );
"update country set name=?",new string);
toast.maketext(this, "更新成功", toast.length_short).show();
system.out.println("更新成功");
database.close();
}//查詢單個資料
private void check() );
//如果還有下乙個
while(cursor.movetonext())
system.out.println("查詢成功");
cursor.close();
database.close();
}//查詢所有資料
private void checkall()
system.out.println("查詢成功");
cursor.close();
database.close();}}
以上就是sqlite資料庫的增刪改查的簡單使用。
安卓中SQLite的簡單使用
sqliteopenhelper 是安卓中建立資料庫的乙個幫助類,至少實現其中的oncreate和onupgrade方法。sqliteopenhelper 的方法 方法作用 oncreate sqlitedatabase db 建立資料庫時呼叫 onupgrade sqlitedatabase db...
安卓中的儲存(SQLite)
sqlite 底層實現c和c 語言,本身是開源軟體版。主要應用在儲存聯絡人 儲存簡訊 備忘錄和手機上的音訊檔案等。優點是 資料安全性比較高,資料也方便管理。相應的api sqlitedatabase 開啟或者關閉資料庫 sqliteopenhelper 工具類 cursor物件 cursoradap...
安卓之sqlite的簡單應用
sqlite是乙個輕量型的資料庫,androidsdk自帶的,說白了,就是你手機裡面有乙個資料庫,但是你看不到,必須root之後才可看到,就這麼簡單。db.execsql create table if not exists aofax id integer primary key autoincr...