Java Android SQLite,从特定行更新特定字段

Java Android SQLite,从特定行更新特定字段,java,android,sqlite,Java,Android,Sqlite,我试图在SQLite中更新我的记录中的一个特定列-该对象具有各种属性,但我只想更新该行中的一个字段。这是我的密码: public boolean updateFavorite(String email, int isFavorite){ SQLiteDatabase db = this.getWritableDatabase(); ContentValues args = new ContentValues(); args.put(EMAIL, email);

我试图在SQLite中更新我的记录中的一个特定列-该对象具有各种属性,但我只想更新该行中的一个字段。这是我的密码:

public boolean updateFavorite(String email, int isFavorite){
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues args = new ContentValues();
    args.put(EMAIL, email);
    args.put(IS_FAV, isFavorite);

    int i = db.update(TABLE_FAVORITES, args, EMAIL + "=" + email, null);

    return i > 0;
}
我将电子邮件用于where子句,即从收藏夹更新记录,将isFavorite设置为(给定值),其中电子邮件是(传入值)

我的查询有一个问题,被logcat捕获,如下所示

android.database.sqlite.SQLiteException: near "@sjisis": syntax error (code 1): , while compiling: UPDATE Favorites SET email=?,isFavorite=? WHERE email=sjkshs@sjisis.com
有人能帮我找出我的代码有什么问题导致这个错误吗


p.S my
FavoriteObject
类除了
email
isFavorite
之外还有其他属性,但在这种情况下,我根本不想更新它们

看起来它在抱怨电子邮件地址,可能是@

试一试


例如,在电子邮件地址周围加上单引号。

看起来它在抱怨电子邮件地址,也许是@

试一试


例如,电子邮件地址周围有单引号。

尝试将where子句中的电子邮件也作为参数,我尝试更改您的代码,但尚未测试:

public boolean updateFavorite(String email, int isFavorite){
SQLiteDatabase db = this.getWritableDatabase();

ContentValues values= new ContentValues();
values.put(EMAIL, email);
values.put(IS_FAV, isFavorite);
//add arguments for where clause
String[] args = new String[]{email};

int i = db.update(TABLE_FAVORITES, values, "EMAIL=?", args);

return i > 0;
}

尝试使where子句中的电子邮件也成为参数,我尝试更改您的代码,但尚未测试:

public boolean updateFavorite(String email, int isFavorite){
SQLiteDatabase db = this.getWritableDatabase();

ContentValues values= new ContentValues();
values.put(EMAIL, email);
values.put(IS_FAV, isFavorite);
//add arguments for where clause
String[] args = new String[]{email};

int i = db.update(TABLE_FAVORITES, values, "EMAIL=?", args);

return i > 0;
}

看起来它在抱怨电子邮件地址,也许是@。也许可以尝试
int i=db.update(表_收藏夹、参数、电子邮件+“=”+电子邮件+”,null)即电子邮件地址周围的单引号..是的,哈哈哈,这都是一个粗心的错误。你可以把这个写在答案里,这样我就可以接受了!谢谢你,迈克!看起来它在抱怨电子邮件地址,也许是@。也许可以尝试
int i=db.update(表_收藏夹、参数、电子邮件+“=”+电子邮件+”,null)即电子邮件地址周围的单引号..是的,哈哈哈,这都是一个粗心的错误。你可以把这个写在答案里,这样我就可以接受了!谢谢你,迈克!