gpt4 book ai didi

android - 更新查询 sqlite - Android

转载 作者:太空宇宙 更新时间:2023-11-03 12:20:21 25 4
gpt4 key购买 nike

我无法在我的 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);

这里是异常(exception),

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"

关于android - 更新查询 sqlite - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17505750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com