android - Android 中的数据库检索导致错误

标签 android database

在我的应用程序中,我必须从数据库中检索数据。我的要求是我必须通过满足我必须对组列应该是家庭的总列求和的条件来检索数据。

我写了这个查询:

public String addhousehold()
{
    long sum = 0;

    Cursor cursor1 = db.rawQuery("SELECT SUM("+(KEY_TOTAL)+") FROM incomexpense WHERE groups=Income", null);

     if(cursor1.moveToFirst())
     {
         sum = cursor1.getLong(0);
     }

     cursor1.close();

     String housetotal=String.valueOf((long)sum);       
     System.out.println("house="+housetotal);

     return housetotal; 
}

但是我得到一个错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.budget1/com.budget1.Report}:
android.database.sqlite.SQLiteException: no such column: Income: , while compiling: SELECT SUM(total) FROM incomexpense WHERE groups=Income.
As I am new to this please help me. Thanks in advance

最佳答案

查询应该是:

Cursor cursor1 = db.rawQuery(
         "SELECT SUM("+(KEY_TOTAL)+") FROM incomexpense WHERE groups='Income'",null);

如果 (Income) 是一个字符串..如果不是,那么您应该确保该列存在..

关于android - Android 中的数据库检索导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11408874/

相关文章:

java - Firebase 云函数错误代码和错误消息在 Android 上始终是 Internal

android - getExtras().getSerializable() 和 getSerializableExtra() 的区别

android - Shell 脚本在 bash 中有效,但在 'adb shell' 中无效

ruby-on-rails - 如何在 ActiveRecord 中加入 SUM

mysql - 应该使用什么组织来表示可以与任意数量的其他类型关联的两种类型的数据?

android - 如何在水平ListView的右边缘添加模糊效果以显示内容较多

java - 单击项目导致 IllegalStateException

database - Windows平台下的Redis

database - 使用 MongoDB Compass 克隆 MongoDB 数据库

ruby-on-rails - 一列中包含多个条目的数据库记录