gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 04:07:17 25 4
gpt4 key购买 nike

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

我写了这个查询:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com