我有一个函数,在该函数中,我希望获取MySQL数据库表的行上的值之和。这是我的密码:
public int getSum(int var) {
int x=0;
// Select All Query
String selectQuery = "SELECT sum(amount) FROM donations WHERE aid = '"+aid+"'";
SQLiteDatabase db = openOrCreateDatabase("shareity", Context.MODE_PRIVATE, null);
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
x = cursor.getInt(0);
} while (cursor.moveToNext());
}
// return contact list
Log.d("id", "Id" + "," + x);
return x;
}我在onCreate()中这样称呼它:
getSum(idk);其中idk是一个整数。但是我的这个返回0。我能知道为什么吗?我想要得到的表的行之和也是整数。
发布于 2015-05-05 05:50:43
终于弄明白了。问题在于SQLite数据库。我不得不使用php文件将数据库从mysql服务器下载到本地Sqlite,然后循环遍历它。
https://stackoverflow.com/questions/30025615
复制相似问题