-3

In the below code i am selecting KEY_ROWID = 12 from my Table, but now i need to select KEY_ROWID greater than 12 but less than 20.how i can specify where clause in the below query.

  mDb.query(true, SQLITE_TABLE, new String[] {
                KEY_ROWID     }, 
                KEY_ROWID + "=?" 
                new String[] {"12"},
                null, null, KEY_ITEM , null);     

i donot want to write rawQuery.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
user3586231
  • 391
  • 4
  • 21
  • Duplicated with http://stackoverflow.com/questions/3271740/how-to-add-where-clause-to-query-on-android – Gaskoin Feb 13 '15 at 07:49

2 Answers2

2

Try this query

mDb.query(true, SQLITE_TABLE, new String[] {
            KEY_ROWID     }, 
            KEY_ROWID + " > ? AND " + KEY_ROWID + " < ?",
            new String[] {"12", "20"},
            null, null, KEY_ITEM , null);
Roadblock
  • 2,041
  • 2
  • 24
  • 38
0

Change your query like this

mDb.query(true, SQLITE_TABLE, new String[] {
            KEY_ROWID     }, 
            KEY_ROWID + ">12 AND "+KEY_ROWID+ " <20", 
            null,
            null, null, KEY_ITEM , null); 

or

mDb.query(true, SQLITE_TABLE, new String[] {
        KEY_ROWID     }, 
        KEY_ROWID + " >? AND " + KEY_ROWID + " <?",
        new String[] {""+12, ""+20},
        null, null, KEY_ITEM , null);
kalyan pvs
  • 14,486
  • 4
  • 41
  • 59
  • when you want to decide the number dynamically, you will be sending in variables and if used in this way as concatenating strings can lead to sql injection attacks. The best way is to send in numbers as arguments. – Roadblock Feb 13 '15 at 09:48