2012-02-02 47 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 

希望它帮助。