Android的SQLite的更新查询不工作? [英] Android SQLite update query not working?
本文介绍了Android的SQLite的更新查询不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
公共无效AddViewCount(字符串chname)
{
字符串selectQuery =UPDATE channel_login SET TimesViewed = TimesViewed + 1 WHERE CHANNELNAME =+ chname;
SQLiteDatabase分贝= this.getWritableDatabase();
光标光标= db.rawQuery(selectQuery,NULL);
System.out.print(计数+ cursor.getCount());}
我m到处此错误消息。能否请您指出的罪魁祸首?
android.database.sqlite.SQLiteException:没有这样的列:SAT1
(code 1):,在编译:UPDATE channel_login SET
TimesViewed = TimesViewed + 1 WHERE CHANNELNAME = SAT1
解决方案
请尝试以下操作:
公共无效AddViewCount(字符串chname)
{
字符串selectQuery =UPDATE channel_login SET TimesViewed = TimesViewed + 1 WHERE CHANNELNAME ='+ chname +';
SQLiteDatabase分贝= this.getWritableDatabase();
光标光标= db.rawQuery(selectQuery,NULL);
System.out.print(计数+ cursor.getCount());}
添加'周围的文本值应该工作。另外,除非你需要将光标数,你可以只使用 db.execSQL(selectQuery);
来执行更新
public void AddViewCount(String chname)
{
String selectQuery = "UPDATE channel_login SET TimesViewed=TimesViewed+1 WHERE channelName="+chname ;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
System.out.print("Count"+cursor.getCount());
}
I m getting this error message. Can you please point out the culprit?
android.database.sqlite.SQLiteException: no such column: Sat1
(code 1):,while compiling: UPDATE channel_login SET
TimesViewed=TimesViewed+1 WHERE channelName=Sat1
解决方案
Try the following:
public void AddViewCount(String chname)
{
String selectQuery = "UPDATE channel_login SET TimesViewed=TimesViewed+1 WHERE channelName='"+chname+"'";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
System.out.print("Count"+cursor.getCount());
}
Adding the ' ' around the text value should work. Also, unless you need the cursor count, you could just use db.execSQL(selectQuery);
to perform the update.
这篇关于Android的SQLite的更新查询不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文