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.

8
  • learn about prepared statements Commented Sep 23, 2016 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... Commented Sep 23, 2016 at 12:12
  • Which database you are talking about? Commented Sep 23, 2016 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... Commented Sep 23, 2016 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. Commented Sep 23, 2016 at 12:31

1 Answer 1

0

You must have to write like this

English='MA''AM'
Sign up to request clarification or add additional context in comments.

6 Comments

So what if words have only String like MAM, i mean word which does not have any ', whether this query work with that words too..
dynamically you have to replace it 'MA''AM'
Can you tell me how can i fire query to get all words which contains ', this would be big help from your side.
SELECT * FROM TableName WHERE FieldName LIKE '%''%'
this will get you all records which contains '
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.