How to escape special characters like ' in sqlite in android
I have a function which is executing a query on a table in SQLite database. I declare a constant: public static final String CANADA_HISTORY = "Canada's History"; . This is stored in a String variable let's say difficulty , I have one query: Cursor c = mDb.rawQuery("select * from Questions_answers where CHAPTERS = '"+difficulty+"'" , null); It is throwing an exception near the apostrophe. Logcat output: I/Database( 1170): sqlite returned: error code = 1, msg = near "s": syntax error D/AndroidRuntime( 1170): Shutting down VM W/dalvikvm( 1170): threadid=1: thread exiting with uncaught exception