2014-10-22 32 views
0

我想在sqlite数据库中一次检索整行。所有这些都是字符串。我写了一个方法。 如果有人可以检查这个错误。 感谢如何在Sqlite中检索整行数据

public ArrayList<Integer> queueAll_row(){ 
     String[] columns = new String[]{Key_row_ID,Key_Customer_name,Key_customer_nic,Key_roof,Key_floor,Key_walls,Key_toilets,Key_No_Rooms,Key_electricity,Key_drinkingWater,Key_status,Key_ownership 
       ,Key_hvBankAcc,Key_loansOfOtherBnks,Key_current_No_Emp,Key_new_Emp,Key_income_source1,Key_income_source2,Key_income_source3}; 
     Cursor cursor = ourDb.query(DB_Table, columns, 
       null, null, null, null, null); 

     ArrayList<Integer> values = new ArrayList<Integer>(); 
     cursor.moveToFirst(); 
     while (cursor.moveToNext()) { 
      values.add(cursor.getInt(0)); 
     } 

     return values; 
    } 
+0

why getint(0)?也许它应该是cursor.getValue()或类似的东西 – 2014-10-22 05:45:49

回答

0

您可能会遇到一个原始查询也从表中获得全行数据库.. ,你可以尝试这个代码..希望这会为你工作。

public ArrayList<Integer> queueAll_row() { 

     String query = "select * from " + DB_Table; 
     Cursor cursor = ourDb.rawQuery(query, null); 

     ArrayList<Integer> values = new ArrayList<Integer>(); 
     if (cursor != null && cursor.getCount() > 0) { 
      cursor.moveToFirst(); 
      while (cursor.moveToNext()) { 
       values.add(cursor.getInt(0)); 
      } 
     } 

     return values; 
    } 
0

步骤: - 1.To店从单个行,你必须使用模型类

2.加下面的代码

公众的ArrayList queueAllRow(){

 String query = "select * from "+DB_Table; 

     Cursor cursor = ourDb.rawQuery(query, null); 

     ArrayList<ModelClass> values = new ArrayList<ModelClass>(); 
     if(cursor.moveToFirst()){ 
      do { 
       ModelClass ob1=new ModelClass(); 
       ob1.setvalue(cursor.getString(cursor.getColumnIndex("COL_NAME"))); 

       //set the values to other data members, same like above 

       values.add(ob1); 
      } while (cursor.moveToNext()); 

     } 

     return values;  

} 
所有值
0

请试试这个,我希望它对你有所帮助。

public ArrayList<ProjectModel> getprojectName() { 
    ArrayList<ProjectModel> values = new ArrayList<ProjectModel>(); 
    String query = "SELECT * from project"; 

    cursor = sqLiteDatabase.rawQuery(query, null); 

    if (cursor != null) { 
     if (cursor.moveToFirst()) { 
      do { 
       values.add(new ProjectModel(cursor.getString(cursor 
         .getColumnIndex("project_id")), cursor 
         .getString(cursor.getColumnIndex("project_name")))); 

      } while (cursor.moveToNext()); 
     } 
    } 

    return values; 
} 

model class 

public class ProjectModel { 
private String project_id; 
private String project_name; 

public ProjectModel(String project_id, String project_name) { 
    super(); 
    this.project_id = project_id; 
    this.project_name = project_name; 
} 

public String getProject_id() { 
    return project_id; 
} 

public String getProject_name() { 
    return project_name; 
}