gpt4 book ai didi

Android SQLite 数据库异常

转载 作者:搜寻专家 更新时间:2023-11-01 08:51:20 27 4
gpt4 key购买 nike

目前我在 android 中的 SQLite 数据库有问题,当我尝试运行比较时,我收到以下错误:引起:android.database.sqlite.SQLiteException: near "@hotmail": syntax error: , while compiling: SELECT DISTINCT _id, userName, password FROM userTable WHERE userName=djdss@hotmail.comAND password=shshsh

我的搜索是:

public boolean getUserNameAndPassword(String userName, String Password) 抛出 SQLException {

    Cursor mCursor =
db.query(true, TABLE_NAME, new String[] {KEY_ROWID,USER,
PWD},USER + "=" + userName + "AND password=" + Password, null,
null, null, null, null);

if (mCursor.getCount() > 0)
{
return true;
}
return false;}

我尝试运行它是:

  boolean signIn = dbHelper.getUserNameAndPassword(mEmail, mPassword);
if (signIn){
Toast.makeText(getBaseContext(),"Sign in successful",Toast.LENGTH_LONG).show();
}else {Toast.makeText(getBaseContext(),"Sign in failed",Toast.LENGTH_LONG).show();}

提前致谢!

最佳答案

您应该使用参数化查询而不是仅仅附加用户名和密码变量,请参见下面的示例:

Cursor mCursor =
db.query(true, TABLE_NAME, new String[] {KEY_ROWID,USER,
PWD},USER + " = ? AND password = ?", new String[]{ userName, Password },
null, null, null, null);

if (mCursor.getCount() > 0)
{
return true;
}
return false;}

关于Android SQLite 数据库异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23116949/

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