Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android sqlite中使用count始终返回1_Android_Sqlite_Count - Fatal编程技术网

在android sqlite中使用count始终返回1

在android sqlite中使用count始终返回1,android,sqlite,count,Android,Sqlite,Count,我正在尝试从Sqlite数据库检索行总数。我使用了下面的代码,但问题是计数始终为1,即使有多行满足条件。谁能告诉我哪里出了问题 public int get_report_entry_area_count(String jobId, String area, String sensor) { String countQuery = "select count(*) from report1 where JobId='" + jobId + "' and

我正在尝试从
Sqlite
数据库检索行总数。我使用了下面的代码,但问题是计数始终为1,即使有多行满足条件。谁能告诉我哪里出了问题

public int get_report_entry_area_count(String jobId, String area,
        String sensor) {

    String countQuery = "select count(*) from report1 where JobId='"
        + jobId + "' and sensor='" + sensor + "'" + " and Area='"
            + area + "'";

    SQLiteDatabase database = this.getWritableDatabase();

    Cursor c = database.rawQuery(countQuery, null);
    c.moveToFirst();
    int total = c.getCount();
    c.close();
    return total;

}     
在android sqlite中使用count始终返回1

因为
c.getCount()
返回提供的
Cursor
中的项数,而不是
count
查询结果

光标
获取计数结果:

c.moveToFirst();
int total = c.getInt(0);
在android sqlite中使用count始终返回1

因为
c.getCount()
返回提供的
Cursor
中的项数,而不是
count
查询结果

光标
获取计数结果:

c.moveToFirst();
int total = c.getInt(0);

可能是条件中的字符串导致了问题,所以请首先仅使用
JobId
where条件进行尝试。让我们知道仍然获得计数1?我尝试了字符串countQuery=“select count(*)from report1”,但仍然是1更改此查询字符串countQuery=“select*from report1,其中JobId='“+JobId+'”和sensor='“+sensor+'”“+”和Area='“+Area+'”;可能是条件中的字符串导致了问题,所以请首先仅使用
JobId
where条件进行尝试。让我们知道仍然获得计数1?我尝试了字符串countQuery=“select count(*)from report1”,但仍然是1更改此查询字符串countQuery=“select*from report1,其中JobId='“+JobId+'”和sensor='“+sensor+'”“+”和Area='“+Area+'”;