gpt4 book ai didi

java - 如何将电子邮件和密码值保存在从选择查询检索到的变量中

转载 作者:太空宇宙 更新时间:2023-11-04 10:46:05 24 4
gpt4 key购买 nike

我正在研究 SQLite 数据库。我已使用选择查询检索了值。

现在我必须将这些值保存在变量中,以便与用户输入的电子邮件和密码进行比较。如何将其保存在 Login.java

中的变量中

查询(MYSQLiteHelper.java)

public user_reg getemail(String ema) {

// 1. get reference to readable DB
SQLiteDatabase db = this.getReadableDatabase();

// 2. build query
Cursor cursor =
db.query(TABLE_USERREGISTRATION, // a. table
COLUMNS, // b. column names
" email = ?", // c. selections
new String[] {
String.valueOf(ema)
}, // d. selections args
null, // e. group by
null, // f. having
null, // g. order by
null); // h. limit

// 3. if we got results get the first one
if (cursor != null)
cursor.moveToFirst();

// 4. build book object
user_reg user = new user_reg();
user.setEmail(cursor.getString(3));
user.setPassword(cursor.getString(4));

Log.d("getUser(" + ema + ")", user.toString());

// 5. return book
return user;
}

登录.java

MySQLiteHelper db = new MySQLiteHelper(getApplicationContext());
emailval= email.getText().toString();
db.getemail(emailval);

最佳答案

您可以通过以下方式从光标获取数据:

// 3. if we got results get the first one
if (cursor != null)
cursor.moveToFirst();

// 4. build book object
user_reg user = new user_reg();

// I am expecting email and password as column name
user.setEmail(cursor.getString(cursor.getColumnIndex("email")));
user.setPassword(cursor.getString(cursor.getColumnIndex("password")));
Log.d("getUser(" + ema + ")", user.toString());

// 5. return book
return user;

关于java - 如何将电子邮件和密码值保存在从选择查询检索到的变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48402688/

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