-1

public ArrayList calculateTotal() {

    SQLiteDatabase db = this.getWritableDatabase();
    ArrayList<Integer> array_list2 = new ArrayList<Integer>();

    Cursor cursor1 = db.rawQuery(
            "SELECT SUM(cost) FROM expense", null);
    if (cursor1.moveToFirst()) {
        columntotal = cursor1.getFloat(0);
    }
    cursor1.close();
    db.rawQuery("INSERT INTO total VALUES(columntotal)", null);

I'm unable to sum up the cost and display in android studio....

1 Answers1

0

Your insert command should be something like below:

"INSERT INTO total VALUES("+columntotal+")"

Its better to use PreparadStatement approach

Community
  • 1
  • 1
kosa
  • 63,683
  • 12
  • 118
  • 157