0
我添加數據到使用此代碼數據庫,如何從SQL數據庫檢索行數據 - Android電子
/**
* Storing deck
* */
public void addDeck(String id, String name, String uid, String did) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_DECK_ID, id); // ID
values.put(KEY_DECK_NAME, name); // Name
values.put(KEY_DECK_UID, uid); // Unique Id
values.put(KEY_DECK_DID, did); // Deck id
// Inserting Row
db.insert(TABLE_DECK, null, values);
db.close(); // Closing database connection
}
現在我希望能夠訪問每一行,我該怎麼辦呢?
這是我當前的代碼來訪問數據庫中的
// Getting deck data from database
public HashMap<String, String> getDeckDetails(){
HashMap<String,String> deck = new HashMap<String,String>();
String selectQuery = "SELECT * FROM " + TABLE_DECK;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// Move to first row
cursor.moveToFirst();
if(cursor.getCount() > 0){
deck.put("id", cursor.getString(1));
deck.put("name", cursor.getString(2));
deck.put("uid", cursor.getString(3));
deck.put("did", cursor.getString(4));
}
cursor.close();
db.close();
// return user
return deck;
}
此代碼只返回第一行的行,我怎麼能得到它返回的每一行?