1

I want to insert a string into the database that contains the character

'

To Insert: Hello I'm Drac.

I tried escape sequence but isn't working. Please help me Figure it out

Here's my Code.

private void insertchathead(String message) {
  String experiment=message.replace("'","\\'");
                Log.e("********","Ending L: --> "+experiment);
  sd.execSQL("insert into chat(message)values('"+experiment+"');");
                Log.e("************","inserted");
 }

The Logcat Shows Syntax error. Here's the Error

     Caused By : SQL(query) error or missing database.
     (near "s": syntax error (code 1): , while compiling: insert  into chat(message) values('what\'s your age');)
  • Big thanks @paulsm – Anshul Aggarwal Aug 12 '17 at 04:41
  • You're welcome. I don't know why my comment was deleted: but to repeat it: the problem wasn't "adding an escape character to a string" (i.e. applying `\\ ` ). Rather, the problem was adding a quote delimiter to a SQL string. The solution was to add a double quote (`''`). Glad it helped :) – paulsm4 Aug 13 '17 at 20:15

0 Answers0