使用字符串值 Android 更新时出现 sqlite 语法错误
sqlite syntax error when updating with string value Android
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" 附近: 语法错误
使用这个,在 where 子句中 ip 和 f1 值应该用单引号引起来
db.execSQL("UPDATE " + Profile.ACCOUNTS_TABLE_NAME + " SET " + SipProfile.FIELD_IP+ "='"+ip +"' WHERE "+ Profile.FIELD_DISPLAY_NAME + "='" + f1+"'");
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" 附近: 语法错误
使用这个,在 where 子句中 ip 和 f1 值应该用单引号引起来
db.execSQL("UPDATE " + Profile.ACCOUNTS_TABLE_NAME + " SET " + SipProfile.FIELD_IP+ "='"+ip +"' WHERE "+ Profile.FIELD_DISPLAY_NAME + "='" + f1+"'");