SQL:无法使count(*)正常工作-为什么呢?

时间:2019-07-16 16:50:50

标签: java android sql

我正在尝试在数据库中查询与给定ID匹配的条目数,但是我无法提出有效的解决方案。

每种类型的帐户都有两个对应于1的userID,出于某种原因,第一种方法输出“ 1”,第二种方法输出“ 0”。如果需要,我还可以显示mainactivity和数据库架构。

public int numberOfDebitAccounts(int userID){
    int numOf_accs = 0;
    String query = "select count(*) from debitAccount where userID = '" +userID+"'";
    openDatabase();
    Cursor cursor = db.rawQuery(query,null);
    if(cursor.moveToFirst()) {
        numOf_accs = cursor.getInt(0);
        System.out.println("Number of debit accs: " + numOf_accs);
    }
    cursor.close();
    closeDatabase();
    return numOf_accs;
}

public int numberOfCreditAccounts(int userID){
    int numOf_accs = 0;
    String query = "select count(accountID) from creditAccount where userID = '" +userID+"'";
    openDatabase();
    Cursor cursor = db.rawQuery(query,null);
    if(cursor.moveToFirst()) {
        numOf_accs = cursor.getInt(0);
        System.out.println("number of credit accounts: " + numOf_accs);
    }
    closeDatabase();
    return numOf_accs;
}

0 个答案:

没有答案