开发者

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 l开发者_开发知识库et'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? '


Have you try this

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


first replace char with this

v=v.replaceAll("'","\'");

then pass it in your query

"select * from xyz where question='"+v+"'";

give a shot


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


Replace all single quotes in v with 2 single quotes :

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜