I am trying to query my database to return the name entered into a text box. I have been able to view all the items in the database but i want to search for a name using a text box. When I enter the name and hit the search button, the log cat displays an error that “no such column: john: while compiling: SELECT name, gender, height, age, hair FROM details WHERE name= john ORDER by name.
private void findRecords(){
EditText find = (EditText)findViewById(R.id.nameSearch);
EditText name = (EditText)findViewById(R.id.nameFound);
EditText gender = (EditText)findViewById(R.id.genderFound);
String s = find.getText().toString();
//Long l = Long.parseLong(s);
DatabaseClass hon = new DatabaseClass(this);
String returnedName = hon.getName(s);
String returnedGender = hon.getGender(s);
name.setText(returnedName);
gender.setText(returnedGender);
}
public String getName(String s) {
// TODO Auto-generated method stub
String[] columns = new String[] {NAME_COLUMN, GENDER_COLUMN, HEIGHT_COLUMN, AGE_COLUMN, HAIR_COLUMN};
Cursor c = sherlockdb.query(TABLE_NAME, columns, NAME_COLUMN +"="+ s, null, null, null, NAME_COLUMN);
if (c != null){
c.moveToFirst();
String name = c.getString(1);
return name;
}
return null;
}
Please kindly help
Try this:
Because you need String in ‘john’ format.