[英]Update Query not working in Android Sqlite
My Java code Update Data base Table 我的Java代码更新数据库表
String qq="UPDATE ChallanItems SET Recieve ="+str+" WHERE ItemNo = "+code;
Log.d("Qry", qq);
myDbHelper.updatequery(qq);
updatequery method updatequery方法
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 当我更新数据库时,计数返回0,并且表未更新
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 提前致谢
Use execSQL()
for such SQL and not rawQuery()
. 对此类SQL使用
execSQL()
,而不是rawQuery()
。
rawQuery()
just compiles the SQL but does not run it. rawQuery()
仅编译SQL但不运行它。 You'd need to call one of the move...()
methods on the returned Cursor
to execute a step of the compiled SQL program. 您需要在返回的
Cursor
上调用move...()
方法之一,以执行已编译SQL程序的步骤。
execSQL()
both compiles and runs the SQL program. execSQL()
编译并运行SQL程序。
There's also possibly a syntax problem with your literals - use parameters ie ?
您的文字可能还存在语法问题-使用参数,即
?
placeholders in SQL and String[]
bind arguments to be safe. SQL和
String[]
占位符绑定参数是安全的。
try to use this: 尝试使用此:
ContentValues values = new ContentValues();
values.put("Recieve", str);
db.update("ChallanItems", values2, "ItemNo = ?", new String[] { code });
To update sqlite query change 更新sqlite查询更改
Cursor c = myDataBase.rawQuery(qry, null);
to this 对此
myDataBase.execSQL(qry);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.