如何在SqlLite中打印/ Toast列值的总和

时间:2017-08-06 15:25:22

标签: android sqlite

我的查询是

Button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int cv;

            String getmont="",getyear="";

            getmont=year.getText().toString();
            getyear= (String) sid.getSelectedItem();
            SQLiteDatabase db;

            db = openOrCreateDatabase("monthapp", MODE_PRIVATE, null);
            curtop = db.rawQuery("SELECT SUM(currentpaid)FROM monthvaluesOrgin WHERE curmonth='" + getmont + "' AND curyear='" + getyear + "'", null);
            if (curtop.moveToNext() ) {

              cv=curtop.getInt(0);
                Toast.makeText(getApplicationContext(),cv,Toast.LENGTH_SHORT).show();


            }


        }
    });

如何打印/烘焙总和值?

它始终显示EOFException

我在try catch中试过但没有工作。

1 个答案:

答案 0 :(得分:0)

假设cursorrawQuery()调用返回的光标。因此,使用它来获得int sum值:

int sum;
if(cursor.moveToFirst()) sum = c.getInt(0); 
else sum = -1;
c.close();

然后你可以随意使用sum