Android的SQLite的SELECT查询Android、SQLite、SELECT

2023-09-04 08:26:04 作者:醉色染红颜

我已经采取了字符串值从的EditText 之后将其设置在 SELECT查询WHERE 条件

I have taken String value from a EditText and set it inside SELECT QUERY after WHERE condition

TextView tv = (TextView) findViewById(R.id.textView3);
EditTextet2 et = (EditText) findViewById(R.id.editText1);

String name = et.getText().toString();

Cursor c = db.rawQuery("SELECT * FROM tbl1 WHERE name = '"+name+"'", null); 

c.moveToNext();

tv.setText(c.getString(c.getColumnIndex("email")));

不过,这是行不通的。有什么建议么?在此先感谢。

But it doesn't work. Any suggestions? Thanks in Advance.

推荐答案

尝试微调的字符串,以确保没有多余的空格:

Try trimming the string to make sure there is no extra white space:

Cursor c = db.rawQuery("SELECT * FROM tbl1 WHERE TRIM(name) = '"+name.trim()+"'", null);

也可以使用 c.moveToFirst()像@thinksteep提及。

Also use c.moveToFirst() like @thinksteep mentioned.