Sqlite查询多个结果

时间:2013-06-11 08:00:14

标签: android sqlite

我想查询sqlite中的数据,但是在2item具有相同名称的情况下..仍然只返回结果...我应该在此代码中添加什么?

  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;

}

1 个答案:

答案 0 :(得分:2)

尝试发送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;
}