0
我有一個存儲用戶的ID(col_id),名稱(col_name)和用戶名(username)的表。下面是我的代碼我用來檢索數據SQL select查詢返回列的名稱
public HashMap<String, String> getUserDetails(){
HashMap<String, String> user = new HashMap<String, String>();
String selectQuery = "SELECT * FROM " + TABLE_COL_DATA;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
cursor.moveToFirst();
if(cursor.getCount() > 0){
user.put("col_id", KEY_ID);
user.put("name", KEY_NAME);
user.put("username", KEY_USERNAME);
}
return user;
}
但是當我登錄檢索數據,它顯示col_id,COL_NAME和用戶名,而不是實際添加的數據。
這是我得到的數據,並記錄它
dbHandler.setCollectorTable(colID, colName, username);
HashMap<String, String> tmpMap = dbHandler.getUserDetails();
Log.d("Retrieved Col ID", tmpMap.get(KEY_COL_ID));
Log.d("Retrieved Col Name", tmpMap.get("name"));
Log.d("Retrieved Col Username", tmpMap.get("username"));
工作正常。謝謝 –
@ThahzanMohomed喲歡迎。 –