我在使用sqlite在Android应用中插入字符串时遇到了麻烦
,
query = "INSERT OR REPLACE into table(_id, text) VALUES ("+data.get(i).id+", '"+data.get(i).text+"')";
MyClass.db.execSQL(query);
如果我的弦看起来像
'I'm an android developer'
应用程式在这里当机,这是logcat结果,
Caused by: android.database.sqlite.SQLiteException: near "m": syntax error: , while compiling: INSERT OR REPLACE into table (_id, text) VALUES (4, '"I'm an android developer"' )
我认为它假设,我的查询到此结束
'"I'
请帮助我插入任何大小写的字符串,它包含单引号或双引号,例如,
"I'm an "android" developer"
没有任何硬编码或任何内容,您可以使用ContentValues
像下面这样直接插入。
ContentValues values = new ContentValues();
long retvalue = 0;
values.put("_id", id_here);
values.put("text", your_text_here);
retvalue = MyClass.db.insertWithOnConflict(table, null, values, CONFLICT_REPLACE);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句