user2149618
user2149618

Reputation: 75

Sqlite query for multiple result

i want to query for data in sqlite, but in the case where 2item have the same name.. still it return only result... what should i add in this code?

  public String getItemNameRbPrice(long lprice) throws SQLException{


String[] column = new String[]{Pro_ID, Pro_Name, Pro_Price, Pro_Description, Pro_Date};
Cursor c = ourDatabase.query(TABLE_NAME, column, Pro_Price + "=" + lprice, null, null, null, null);

if(c != null){
    c.moveToFirst(); 
    String name = c.getString(1);
    Log.v(name,name + ("zz"));
    return name;
}
return null;

}

Upvotes: 0

Views: 386

Answers (1)

MDMalik
MDMalik

Reputation: 4001

Try sending List<String>

 public List<String> getItemNameRbPrice(long lprice) throws SQLException{
       String[] column = new String[]{Pro_ID, Pro_Name, Pro_Price, Pro_Description, Pro_Date};
       Cursor c = ourDatabase.query(TABLE_NAME, column, Pro_Price + "=" + lprice, null, null, null, null);
       List<String> lst = new ArrayList<String>();
    if (cursor.moveToFirst()) {
        do {
            String name = c.getString(1);
            lst.add(name);

            Log.v(name,name + ("zz"));
        } while (cursor.moveToNext());
    }
           return lst;
}

Upvotes: 2

Related Questions