2013-05-01 78 views
0
public ArrayList <PatientInfo> getAllPatients(String username) { 
    ArrayList <PatientInfo> patients = new ArrayList <PatientInfo>(); 

    open(); 

    Cursor cursor = db.query(UserTable, null, null, null, null, null, AccessedDate); 
    while (cursor != null && cursor.moveToNext()) { 
     try { 

     } catch (Exception ex) { 
      //Log.e("XXX", ex.getMessage()); 
     } 
    } 
    if (cursor != null) 
     cursor.close(); 
    close(); 

    Collections.reverse(patients); 
    return patients; 
} 

我在我的方法中獲取用戶名作爲參數,我如何根據用戶名查詢我的表並獲得user specific resultAndroid:基於用戶名的sqlite查詢

回答

2

正如您從the documentation所看到的,query()的第三個和第四個參數是選擇和選擇參數。

所以,你想是這樣的:

Cursor cursor = db.query(UserTable, null, 
          "username=?", new String[] {username}, 
          null, null, AccessedDate); 

根據需要編輯在你的表相匹配相關列的實際名稱的第三個參數。