So im trying to build a search method for my android app and i keep running into this error
android.database.sqlite.SQLiteException: near "Prefect": syntax error (code 1):
while compiling: SELECT * FROM Person WHERE name = Ford Prefect
This is the method i have that is running the query
public Cursor findUser(String uName)
{
Cursor res = myDatabase.query("Person WHERE name = "+uName+"",
null,null,null,null,null,null);
return res;
}
And the String uName comes from this method
public void onClick(View v)
{
EditText uNameField = (EditText)findViewById(R.id.editText);
String userName=uNameField.getText().toString();
switch (v.getId())
{
case R.id.button:
Intent myIntent = new Intent(FindUser.this,
Results.class);
myIntent.putExtra("uName", userName);
startActivity(myIntent);
break;
}
}
Can anyone help with my im getting this error?? everything seems to be fine i just cant understand why it stops on the surname. But the usernames are correctly formatted like so "Ford Prefect"
Aucun commentaire:
Enregistrer un commentaire