0

I have a hashmap method which is;

    public HashMap<String, String> getUserDetails(){
        HashMap<String,String> user = new HashMap<String,String>();
        String selectQuery = "SELECT  * FROM " + TABLE_LOGIN;

        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);
        // Move to first row
        cursor.moveToFirst();
        if(cursor.getCount() > 0){
            user.put("name", cursor.getString(1));
            user.put("email", cursor.getString(2));
            user.put("uid", cursor.getString(3));
            user.put("created_at", cursor.getString(4));
        }
        cursor.close();
        db.close();
        // return user
        return user;
    }

I have a string email and I want to get the email of the method where id=10. How can I set the email equal to that certain String basicly; String email = getUserDetails(email Where id=10) I know I'm way off, but you get the idea.

3
  • 2
    How do you think the extra tags and a somewhat ambiguous question will help? Commented Feb 8, 2014 at 9:07
  • SELECT name, email, uid, created_at FROM my_table WHERE id = 10? Commented Feb 8, 2014 at 9:07
  • docs.oracle.com/javase/tutorial/java/javaOO/arguments.html Commented Feb 8, 2014 at 10:20

1 Answer 1

2
public HashMap<String, String> getUserDetails(int id){
  HashMap<String,String> user = new HashMap<String,String>();
  String selectQuery = "SELECT  * FROM " + TABLE_LOGIN + " WHERE id=" + id + ";";
  SQLiteDatabase db = this.getReadableDatabase();
  Cursor cursor = db.rawQuery(selectQuery, null);
  // Move to first row
  cursor.moveToFirst();
  if(cursor.getCount() > 0){
      user.put("name", cursor.getString(1));
      user.put("email", cursor.getString(2));
      user.put("uid", cursor.getString(3));
      user.put("created_at", cursor.getString(4));
  }
  cursor.close();
  db.close();
  // return user
  return user;
}

to use it :

String email = getUserDetails(10).get("email");
Sign up to request clarification or add additional context in comments.

1 Comment

the first parameter is int, getUserDetails().get("email"); works but I get compiling errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.