Note that there are some explanatory texts on larger screens.

plurals
  1. PONo such Column error when trying to execute two conditions using where
    text
    copied!<p>I am newbie to android development.In my project I am trying to get the count of number of rows using following query.I got (1)No such column:column_name error.This is my logcat,</p> <pre><code>no such column: userid (code 1): , while compiling: select count(*) from Messages where userid = userr AND statusy = status 12-18 12:48:13.776: E/AndroidRuntime(1372): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 12-18 12:48:13.776: E/AndroidRuntime(1372): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882) 12-18 12:48:13.776: E/AndroidRuntime(1372): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493) 12-18 12:48:13.776: E/AndroidRuntime(1372): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 12-18 12:48:13.776: E/AndroidRuntime(1372): at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58) 12-18 12:48:13.776: E/AndroidRuntime(1372): at android.database.sqlite.SQLiteQuery.&lt;init&gt;(SQLiteQuery.java:37) 12-18 12:48:13.776: E/AndroidRuntime(1372): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) </code></pre> <p>This is my table creation statement,</p> <pre><code> String CREATE_MESSAGES_TABLE = "CREATE TABLE " + TABLE_MESSAGES + "(" + KEY_USERID + " TEXT," + KEY_ID + " INTEGER PRIMARY KEY," + KEY_FROM + " TEXT," + KEY_TO + " TEXT," + KEY_BODY + " TEXT," + KEY_DATE + " TEXT," + KEY_STATUS + " TEXT" + ")"; db.execSQL(CREATE_MESSAGES_TABLE); </code></pre> <p>And this is my query,</p> <pre><code> public int Get_Total_Contacts() { String countQuery="select count(*) from " + TABLE_MESSAGES + " where " + KEY_USERID + " = userr AND " + KEY_STATUS + " = status"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(countQuery, null); int a=cursor.getCount(); cursor.close(); return a; } </code></pre> <p>Can anyone help me where I made mistake?</p> <p>Thanks!!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload