Sqlite数据库更新一行android [英] Sqlite database updating a row android
本文介绍了Sqlite数据库更新一行android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个Android应用程序,其中我需要更新一个表中的列基于某个where子句。下面的代码,
I am developing an android app, in which I need update a column in a table based on the a certain where clause.Here is the code below,
public void updatethekeyofweeklycolumn(String profilename, String keystemp)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Profile_keysofweekly, keystemp);
db.update(TABLE_PROFILE_SETTINGS_FOR_WEEKLY, values,Profile_Name_for_weekly +" = "+profilename, null);
}
上面的代码正常工作,where子句为null,强制关闭与whereclause设置。我的查询是否错误?
The above code is working fine with where clause as null, but its throwing a force close with the whereclause is set. Is my Query wrong?
推荐答案
您需要转义profilename。因此,您可以添加单个字符:
You need to escape profilename. So you either add the single ' character:
db.update(TABLE_PROFILE_SETTINGS_FOR_WEEKLY, values,Profile_Name_for_weekly +" = '"+ profilename + "'", null);
或者,我会选择以下选项:
Or, the option I would follow:
db.update(TABLE_PROFILE_SETTINGS_FOR_WEEKLY, values,Profile_Name_for_weekly +" = ?", new String[] {profilename});
这篇关于Sqlite数据库更新一行android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文