产生的原因:android.database.sqlite.SQLiteException:没有这样的柱:L
问题描述:
Caused by: android.database.sqlite.SQLiteException: no such column: kia (code 1): , while compiling: UPDATE people_chat SET msg = kia WHERE name = uol
final String CREATE_QUERY4 = "CREATE TABLE IF NOT EXISTS "+PEOPLE_CHAT+ "("+ "id INTEGER primary key autoincrement,"+ "name TEXT NOT NULL ,"+ "msg TEXT NOT NULL "+ ")";
列表项产生的原因:android.database.sqlite.SQLiteException:没有这样的柱:L
public void upDateMsg(String name,String msg){
Log.i(TAG, "UpdateData: "+msg);
String strSQL = "UPDATE people_chat SET msg = "+msg+" WHERE name = "+ name;
db.execSQL(strSQL);
Log.i(TAG, "Update Success: "+strSQL);
}
}
答
它应该是:
UPDATE people_chat SET msg = 'kia' WHERE name = 'uol'
你缺少单引号。更改代码:
String strSQL = "UPDATE people_chat SET msg = '"+msg+"' WHERE name = '"+ name+"'";
注:正如指出的意见,如果名称中包含单引号,则查询会失败。它必须相应地逃脱。
+0
当一个字符串包含一个引号时,这将炸毁。 –
添加代码片段以及登录猫 –
为什么你不使用ContentValues? http://stackoverflow.com/questions/9798473/sqlite-in-android-how-to-update-a-specific-row –
将查询更改为'String strSQL =“UPDATE people_chat SET msg ='”+ msg +“'WHERE name ='“+ name +”'“;' –