更新查询sqlite – Android

前端之家收集整理的这篇文章主要介绍了更新查询sqlite – Android前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我无法在我的 Android应用程序中破解sqlite中的简单更新查询..这是查询,

int fav = 1;
Cursor c = sqliteDB.rawQuery("UPDATE "+ MyConstants.TABLE_NAME + " SET "+MyConstants.TABLE_NAME+"."+MyConstants.ISFAV+ " = "+fav+ " WHERE " +MyConstants.TABLE_NAME+"."+MyConstants.WORD_NAME+ " = \""+word_name+"\"",null);

这是例外,

07-06 23:41:48.723: E/AndroidRuntime(1102): FATAL EXCEPTION: main
07-06 23:41:48.723: E/AndroidRuntime(1102): android.database.sqlite.sqliteException: near ".": Syntax error (code 1):,while compiling: UPDATE words SET words.isfavor = 1 WHERE words.word = "hello"
07-06 23:41:48.723: E/AndroidRuntime(1102):     at android.database.sqlite.sqliteConnection.nativePrepareStatement(Native Method)
07-06 23:41:48.723: E/AndroidRuntime(1102):     at android.database.sqlite.sqliteConnection.acquirePreparedStatement(sqliteConnection.java:1013)
07-06 23:41:48.723: E/AndroidRuntime(1102):     at android.database.sqlite.sqliteConnection.prepare(sqliteConnection.java:624)
07-06 23:41:48.723: E/AndroidRuntime(1102):     at android.database.sqlite.sqliteSession.prepare(sqliteSession.java:588)
07-06 23:41:48.723: E/AndroidRuntime(1102):     at android.database.sqlite.sqliteProgram.<init>(sqliteProgram.java:58)
07-06 23:41:48.723: E/AndroidRuntime(1102):     at android.database.sqlite.sqliteQuery.<init>(sqliteQuery.java:37)
07-06 23:41:48.723: E/AndroidRuntime(1102):     at android.database.sqlite.sqliteDirectCursorDriver.query(sqliteDirectCursorDriver.java:44)

解决方法

你不断使用表名.它应该更像是这样的:

int fav = 1;
Cursor c = sqliteDB.rawQuery("UPDATE "+ MyConstants.TABLE_NAME + " SET "+ MyConstants.ISFAV + " = "+fav+ " WHERE " + MyConstants.WORD_NAME + " = \""+word_name+"\"",null);

这应该给你一个看起来更像这样的结果查询

UPDATE words SET isfavor = 1 WHERE word = "hello"
原文链接:https://www.f2er.com/sqlite/822987.html

猜你在找的Sqlite相关文章