Android的SQLite的SELECT查询 [英] Android SQLite SELECT Query

查看:144
本文介绍了Android的SQLite的SELECT查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经采取了字符串值从的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.

这篇关于Android的SQLite的SELECT查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆