Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Query not working in Android Sqlite

My Java code Update Data base Table

String qq="UPDATE ChallanItems SET Recieve ="+str+" WHERE ItemNo = "+code;
                    Log.d("Qry", qq);
                     myDbHelper.updatequery(qq);

updatequery method

public void updatequery(String qry)
    {
        Cursor c = myDataBase.rawQuery(qry, null);


        Log.d("Up", ""+c.getCount());
    }

When i updated Data base the count return 0 and table not updated

I am using this Also but not work

String qq="UPDATE ChallanItems SET Recieve ="+str+" WHERE ItemNo = "+"'"+code+"'";

Please Help Me how i can fix this problem

Thanks In Advance

like image 380
Kuldeep Avatar asked Mar 27 '26 05:03

Kuldeep


2 Answers

Use execSQL() for such SQL and not rawQuery().

rawQuery() just compiles the SQL but does not run it. You'd need to call one of the move...() methods on the returned Cursor to execute a step of the compiled SQL program.

execSQL() both compiles and runs the SQL program.

There's also possibly a syntax problem with your literals - use parameters i.e. ? placeholders in SQL and String[] bind arguments to be safe.

like image 64
laalto Avatar answered Mar 28 '26 19:03

laalto


To update sqlite query change

 Cursor c = myDataBase.rawQuery(qry, null);

to this

myDataBase.execSQL(qry);
like image 27
Giru Bhai Avatar answered Mar 28 '26 20:03

Giru Bhai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!