SQLiteOpenHelper:
是一個(gè)抽象類,有兩個(gè)抽象方法onCreate和onUpgrade在自己幫助類重寫這兩個(gè)方法。
SQLiteOpenHelper中兩個(gè)非常重要的實(shí)例getReadableDataBase()和getWritableDatabase()這兩種方法創(chuàng)建或打開一個(gè)現(xiàn)有的數(shù)據(jù)庫(如果已經(jīng)存在直接打開,否則創(chuàng)建新的),并返回一個(gè)可對(duì)數(shù)據(jù)庫進(jìn)行讀寫操作的對(duì)象檩小。當(dāng)數(shù)據(jù)庫不可以寫入的時(shí)候,getReadableDataBase()方法返回的對(duì)象將以只讀的方式打開getWritableDatabase()將會(huì)出現(xiàn)異常
query
增刪查改
可以用
Cursor cursord=db.query("LastUser",null,null,null,null,null,null);
Cursor cursor=db.query("User",new String[]{"account","password","status"},null,null,null,null,null);
if (cursor.moveToFirst()){
do {
String status=cursor.getString(cursor.getColumnIndex("status"));
String account=cursor.getString(cursor.getColumnIndex("account"));
String password=cursor.getString(cursor.getColumnIndex("password"));
if (cursord.moveToFirst()){
String lastaccount=cursord.getString(cursord.getColumnIndex("account"));
if(status.equals("true")&&account.equals(lastaccount)){
maccount.setText(account);
mpassword.setText(password);
mchbox.setChecked(true);
}while (cursord.moveToNext());
}
}while (cursor.moveToNext());
}//遍歷查詢數(shù)據(jù)