title: How to escape special characters like ' in sqlite in android
body: <p>I have a function which is executing a query on a table in SQLite database.  I declare a constant: <code>public static final String CANADA_HISTORY = "Canada's History";</code>. This is stored in a <code>String</code> variable let's say <code>difficulty</code>,</p>
  
  <p>I have one query:</p>
  
  <pre><code>Cursor c = mDb.rawQuery("select * from Questions_answers where CHAPTERS = '"+difficulty+"'" , null);
  </code></pre>
  
  <p>It is throwing an exception near the apostrophe.</p>
  
  <p>Logcat output:</p>
  
  <pre><code>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 (group=0x40015560)
  E/AndroidRuntime( 1170): FATAL EXCEPTION: main
  E/AndroidRuntime( 1170): android.database.sqlite.SQLiteException: near "s": syntax error: , while compiling: select * from Questions_answers where CHAPTERS  = 'Canada's History'
  </code></pre>
  
  <p>I have also tried:</p>
  
  <pre><code>1.  difficulty=difficulty.replaceAll("'","''");
  2.  difficulty=difficulty.replaceAll("'","\'");
  3.  difficulty = DatabaseUtils.sqlEscapeString(difficulty);
  </code></pre>
  
  <p>To add to that, it's working me for the single words like <code>Canada History</code>, I mean without the special character word.</p>
  
  <p>Please give me advice for the solve   problem Thanks.</p>