gpt4 book ai didi

java - 调用hashmap映射

转载 作者:行者123 更新时间:2023-12-02 06:14:02 25 4
gpt4 key购买 nike

我有一个 hashmap 方法;

    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;
}

我有一个字符串电子邮件,我想获取 id=10 的方法的电子邮件。我怎样才能将电子邮件设置为等于某个字符串?String email = getUserDetails(emailWhere id=10) 我知道我偏离了,但你明白了。

最佳答案

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;
}

使用它:

String email = getUserDetails(10).get("email");

关于java - 调用hashmap映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21644078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com