2014-10-22 2 views
0

sqlite 데이터베이스에서 한 번에 전체 행을 검색하려고합니다. 모두 문자열입니다. 나는 방법을 썼다. 누구든지이 오류를 확인할 수 있다면. 감사Sqlite에서 전체 Row 행을 검색하는 방법

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

왜 getint (0)입니까? 어쩌면 그것은 cursor.getValue() 또는 비슷한 있어야합니다. –

답변

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 저장소 당신이 코드

공공 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;  

} 
다음 모델 클래스를

2.add를 사용할 필요가 단일 행의 모든 ​​값

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; 
} 
관련 문제