我有表用户,它具有以下属性:
private static final String COLUMN_UID = "id";
private static final String COLUMN_NAME = "name";
private static final String COLUMN_EMAIL = "email";
private static final String COLUMN_PASSWORD = "password";
private static final String COLUMN_LEVEL_ONE_SCORE = "score_1";
private static final String COLUMN_LEVEL_TWO_SCORE = "score_2";
private static final String COLUMN_LEVEL_THREE_SCORE = "score_3";
我希望用户输入他/她的电子邮件以检索score_1,score_2和score_2
我尝试了这些代码,但它不起作用!!
DbHelper db=new DbHelper(this);
final EditText email = (EditText) findViewById(R.id.emailSer);
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String s1= email.getText().toString();
db.getsearch(s1);
}
});
,搜索功能是:
public String getsearch(String email)
{
dbase = this.getReadableDatabase();
Cursor cursor = dbase.rawQuery("select "+ COLUMN_LEVEL_ONE_SCORE +COLUMN_LEVEL_TWO_SCORE + COLUMN_LEVEL_THREE_SCORE +
" from user where email ' "+email+"'",null);
StringBuffer buffer = new StringBuffer();
while (cursor.moveToNext())
{
int index1 = cursor.getColumnIndex(COLUMN_LEVEL_ONE_SCORE);
int index2 = cursor.getColumnIndex(COLUMN_LEVEL_TWO_SCORE);
int index3 = cursor.getColumnIndex(COLUMN_LEVEL_THREE_SCORE);
String s1 = cursor.getString(index1);
String s2 = cursor.getString(index2);
String s3 = cursor.getString(index3);
buffer.append(s1 + " " + s2 + " " + s3);
cursor.moveToNext();
}
return buffer.toString();
}
答案 0 :(得分:0)
将您的选择语句更改为:
dbase.rawQuery("select "+COLUMN_LEVEL_ONE_SCORE"+", "+COLUMN_LEVEL_TWO_SCORE+", "+COLUMN_LEVEL_THREE_SCORE+" from user where email = '"+email+"'",null);
似乎只是SQL语法不正确的问题。