title: Getting id of a row in SQLite in android
body: <p>In my application I want to get the id of a particular row. I am using the following code:</p>
  
  <pre><code>public String getid(String  heading) throws SQLException
      {
          System.out.println("ddbpos="+heading);
          long recc=0;
          String rec=null;
          Cursor mCursor = db.rawQuery(
                   "SELECT id  FROM  savedstoriestable WHERE heading="+heading , null);
      if (mCursor != null) 
      {
      mCursor.moveToFirst();
      recc=mCursor.getLong(0);
      rec=String.valueOf(recc);
      }
      return rec;
      }
  </code></pre>
  
  <p>My database looks like this:</p>
  
  <pre><code>id      heading                                              Description                                    
  1       Congress countdown for 2014 polls:                   ghdfsfdghsdjfsdfhds
          Possibility of UPA-III hinges on how other         
  </code></pre>
  
  <p>But it is showing "<code>Force to close</code>" error:</p>
  
  <p>My Logcat is as follows:</p>
  
  <pre><code>12-24 12:02:10.733: E/AndroidRuntime(22030): Uncaught handler: thread main exiting due to uncaught exception
  12-24 12:02:10.804: E/AndroidRuntime(22030): android.database.sqlite.SQLiteException: near "countdown": syntax error: , while compiling: SELECT id  FROM  savedstoriestable WHERE heading=Congress countdown for 2014 polls: Possibility of UPA-III hinges on how other parties fare
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.database.sqlite.SQLiteProgram.native_compile(Native Method)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:59)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.database.sqlite.SQLiteQuery.&lt;init&gt;(SQLiteQuery.java:49)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:49)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1221)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1194)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at com.newspaper.DBadapter.getid(DBadapter.java:104)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at com.newspaper.SavedStoriesActivity.onOptionsItemSelected(SavedStoriesActivity.java:72)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.app.Activity.onMenuItemSelected(Activity.java:2170)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:139)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:525)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.view.View.onTouchEvent(View.java:4179)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.widget.TextView.onTouchEvent(TextView.java:6541)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.view.View.dispatchTouchEvent(View.java:3709)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.os.Handler.dispatchMessage(Handler.java:99)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.os.Looper.loop(Looper.java:123)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at android.app.ActivityThread.main(ActivityThread.java:4363)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at java.lang.reflect.Method.invokeNative(Native Method)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at java.lang.reflect.Method.invoke(Method.java:521)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  12-24 12:02:10.804: E/AndroidRuntime(22030):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Help me to solve this. Thanks in advance.</p>