vendredi 1 avril 2016

like query in sqlite android not working properly

The following is my function:

public Cursor get_names(String n){
    SQLiteDatabase db = this.getReadableDatabase();

    //" select * from Record where name like  '"
    String query = " select * from Record where name like  '"+n+"' ORDER BY name";

    Cursor res =  db.rawQuery(query,null);
    return res;
}

To this function i send, n like:

String name = element.getText().toString(); 
if(name.length()!=0){
                name = name+"%";
            }
            else
            {
                name="%";
            }
            Cursor display = dbms.get_names(name);

This is working fine if the name matches in the database, But the query is not working if the name does not match..

How do if find the name received by the edittext is matching in the database or not..

Aucun commentaire:

Enregistrer un commentaire