Reputation: 1005
I have a table which stores the ID (col_id), Name (col_name) and Username (username) of a user. Below is my codes I used to retrieve the data
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;
}
But when I log the retrieving data, it shows col_id, col_name and username instead of actual added data.
This is how I get the data and log it
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"));
Upvotes: 0
Views: 63
Reputation: 47807
You want to get Data from Cursor first. and then try to put data into HashMap
like below:
if(cursor.getCount() > 0){
user.put("col_id", cursor.getInt(0));
user.put("name",cursor.getstring(1));
user.put("username", cursor.getstring(2));
}
And go to Cursor. There are many methods available for getting data from Cursor .
Upvotes: 3