使用字符串值Android更新时出现sqlite语法错误

时间:2015-03-14 04:16:46

标签: android android-sqlite

public class Profile implements Parcelable {

public final static String ACCOUNTS_TABLE_NAME = "accounts";
public final static String FIELD_DISPLAY_NAME = "displayname";
public final static String FIELD_IP = "ipaddress";
}



String f1 = "planet";
String ip = "udp:85.59.123.78:289";

我的更新查询如下所示

db.execSQL("UPDATE " + Profile.ACCOUNTS_TABLE_NAME + " SET " + SipProfile.FIELD_IP+ "="+ip +" WHERE "+ Profile.FIELD_DISPLAY_NAME + "=" + f1);

我收到以下错误

03-14 09:28:59.720:E / SQLiteLog(13321):( 1)接近“:85”:语法错误

1 个答案:

答案 0 :(得分:1)

使用这个,在where子句中,ip和f1值应该用单引号

db.execSQL("UPDATE " + Profile.ACCOUNTS_TABLE_NAME + " SET " + SipProfile.FIELD_IP+ "='"+ip +"' WHERE "+ Profile.FIELD_DISPLAY_NAME + "='" + f1+"'");