String updateQuery = "UPDATE Bookdetails SET lastchapter = " + test + " WHERE bookpath=" +sentFilename;
db.execSQL(updateQuery);
错误:
03-04 13:36:23.997: I/System.out(9722): android.database.sqlite.SQLiteException:
near "/": syntax error: , while compiling: UPDATE Bookdetails SET lastchapter =
mukund WHERE bookpath=/mnt/sdcard/Download/What's so great about the doctrine of
grace.epub errors happens
错误发布在上面
我的表包含字段ID,bookpath和lastchapter,book路径包含值
/mnt/sdcard/Download/What's so great about the doctrine of grace.epub
/mnt/sdcard/Download/1b4fdaac-f31d-41e8-9d15-26c9078d891f.epub
/mnt/sdcard/Download/Commentary on Romans.epub
和lastchapter包含值什么都没有
id包含1 2 3
为什么错误发生在"/"
我的更新查询中没有哈希它只存在于存储bookpath的字符串?这是一个错误吗?
答案 0 :(得分:6)
SQL中的字符串文字需要在''
引号中。
但是,对于这样的文字,最好使用?
占位符:
String updateQuery = "UPDATE Bookdetails SET lastchapter=? WHERE bookpath=?";
db.execSQL(updateQuery, new String[] { test, sentFilename });
答案 1 :(得分:1)
我相信你的最后一章& bookpath的类型为String(TEXT)。因此,当您添加或更新它的值时,您应该始终使用'
(单个婴儿床)。将您的查询更改为此
String updateQuery = "UPDATE Bookdetails SET lastchapter ='" + test + "' WHERE bookpath='" +sentFilename + "'";
db.execSQL(updateQuery);
但是,不建议在developer.android.com上直接执行SQL查询,因此您可以使用下面代码之类的替代方法,
String updateQuery = "UPDATE Bookdetails SET lastchapter=? WHERE bookpath=?";
db.execSQL(updateQuery, new String[] { test, sentFilename });