lundi 9 mars 2015

How to use group by sqlite query in Android

In sqlite the group by query works...but in android the query doesn't work...how to use group by query in android.


The error says: Syntax error,Delete this token(Group by bname),


SELECT boname,bname,SUM(amount) FROM Auction where boname ="+boatno.getText().toString() Group by bname,null)


protected void adddata1() {



Database db=new Database(getActivity());
SQLiteDatabase sb=db.getReadableDatabase();



Cursor cus=sb.rawQuery("SELECT boname,bname,SUM(amount) FROM Auction where boname ="+boatno.getText().toString() Group by bname,null);//the problem line

cus.moveToFirst();

int j=0,k=0;
for(int i=0;i<cus.getCount();i++)
{

if(cus.getString(0).toString().equalsIgnoreCase(boatno.getText().toString()))
{
//Toast.makeText(getApplicationContext(), "entered",Toast.LENGTH_LONG).show();

bn.setText(cus.getString(1));
Log.e("", cus.getString(1));

amount.setText(cus.getString(2));

Log.e("", cus.getString(2));
adddata();
tr1.removeAllViewsInLayout();
adddata();
search.setClickable(false);

j++;
}
else
{

}


cus.moveToNext();

}

if(j==0)
{
Toast.makeText(getActivity(), "There is no data's on such Boat's",Toast.LENGTH_LONG).show();
}



}

Aucun commentaire:

Enregistrer un commentaire