2012-02-02 42 views
0

我有一個用表名「Accounts」創建的數據庫有三列。一個被命名爲userId,另一個被命名爲accountType。第三個帳戶是accountId我想創建功能是從Sqlite查詢數據庫獲取項目

 private int getNextAccountIdForUserId (String ourUserId, int ourAccountType) 
      { 
       int nextId = kFirstIDValue; 
       Cursor mCursor = mDb.query(true, ACCOUNT_TABLE, new String[] {"userId", accountType},"accountId", null, null, null, null, null); 
       ... 
       //what more to do to get the accountId of ourUserId and ourAccountType 

      } 

我想檢索我已經定義的特定ACCOUNTTYPE和用戶id的帳戶ID。請告訴正確的所用查詢的合成者。

回答

0

您可以使用SQL象下面這樣:

String sql = "SELECT userId, accountType, accountId FROM Accounts WHERE accountId ="+accountId; 
Cursor mCur = mDb.rawQuery(sql , null); 
0

你可以使用:

Cursor mCursor = mDb.query(true,ACCOUNT_TABLE, new String[] {"userId","accountId", "accountType"},"userId='"+sp_userid+"' and accountType='"+sp_accounttype+"'", null, null, null, null, null); // sp_userid and sp_accounttype are the specific userid and accounttype 
0

嘗試使用以下內容:

Cursor cursor = getDB().rawQuery("select accountid from accounts where accountType=? and userId=?", new String[] { accountType,userid}); //your variables in the array 

希望它幫助。