mercredi 23 mars 2016

Retrive some columns from a given emai

I have table user which have the following attributes:

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";

I want the user enter his/her email to retrive score_1, score_2 and score_2

I tried this codes, but it dose not work!!

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);
        }
    });

and the search function is:

    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();
}

Aucun commentaire:

Enregistrer un commentaire