Reputation: 18489
I have a function which is executing a query on a table in SQLite database.I have one what like " what's your name ?" .This is stored in a String variable let's say v, I have one query like "Select * from xyz where question=" ' "+v+" ' "; .But it is throwing some exception near appos s. Any solution will be appreciated.
Is is showing error : whilke compiling : select * from xyz where quesion='what's your name? '
Upvotes: 0
Views: 3690
Reputation: 33996
Have you try this
VALUE = DatabaseUtils.sqlEscapeString(VALUE);
"select * from xyz where question="+ VALUE;
Upvotes: 2
Reputation: 552
Replace all single quotes in v with 2 single quotes :
String q = "select * from xyz where question = '" + v.replaceAll("'","''") + "'";
Upvotes: 0
Reputation: 42016
first replace char with this
v=v.replaceAll("'","\'");
then pass it in your query
"select * from xyz where question='"+v+"'";
give a shot
Upvotes: 1