Android Killer
Android Killer

Reputation: 18489

SQLite query problem with special character

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

Answers (4)

Dharmendra
Dharmendra

Reputation: 33996

Have you try this

VALUE = DatabaseUtils.sqlEscapeString(VALUE);
"select * from xyz where question="+ VALUE;

Upvotes: 2

Ben
Ben

Reputation: 552

Replace all single quotes in v with 2 single quotes :

String q = "select * from xyz where question = '" + v.replaceAll("'","''") + "'";

Upvotes: 0

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

Rasel
Rasel

Reputation: 15477

try this "select * from xyz where question='"+v+"'"

Upvotes: 0

Related Questions