0

I am trying to execute query like

Select  * From Table_name where English=' + word + "'"

and error i am getting is

09-23 07:41:21.995: E/AndroidRuntime(4693): android.database.sqlite.SQLiteException: near "AM": syntax error (code 1): , while compiling: Select  * From Table_Name where English='MA'AM'

I have refered the link android.database.sqlite.SQLiteException: near "...": syntax error (code 1) but that also gives me error like

09-23 08:27:08.710: E/AndroidRuntime(5581): android.database.sqlite.SQLiteException: near "MA": syntax error (code 1): , while compiling: Select  * From Tabel_Name where English=?MA'AM

So my question is how can i pass this query with MA'AM this kind of words.

PS: Other words which does not have ' is working fine so there is no issue with any other code, just query only which is creating problem.

Thanks in advance.

Community
  • 1
  • 1
  • learn about prepared statements – Jens Sep 23 '16 at 12:03
  • @Jens, I am android developer so i dont have much knowledge of SQL, but still if you can provide any URL or example that would be better to understand the scenario... – user3686177 Sep 23 '16 at 12:12
  • Which database you are talking about? – Jens Sep 23 '16 at 12:25
  • @laalto, i am getting error if i use the query like in that question... So please do not mark this question as duplicate.. That this is different scenario... – user3686177 Sep 23 '16 at 12:29
  • It's the same: `'` in a SQL string literal is a problem and the best solution is to use `?` variables and bind the values. – laalto Sep 23 '16 at 12:31
  • @laalto, Even i have tried with **?** also but still i am getting the same error, i have updated my question also with that error – user3686177 Sep 23 '16 at 12:34
  • @laalto, Can you tell me how can i fire query to get all words which contains ', this would be big help from your side – user3686177 Sep 23 '16 at 12:47
  • Don't include the `MA'AM` in the SQL at all - just the `?`. The value `MA'AM` should go in `selectionArgs`. – laalto Sep 23 '16 at 14:09

1 Answers1

0

You must have to write like this

English='MA''AM'
Bharat
  • 2,441
  • 3
  • 24
  • 36