gpt4 book ai didi

Android sqlite 更新问题

转载 作者:IT王子 更新时间:2023-10-29 06:28:43 25 4
gpt4 key购买 nike

如果我的问题太简单,请向我道歉,并指导我更新声明中的错误。

我有 sqlite 将我的记录存储在 android 应用程序中。我能够成功插入和选择。但是,在更新期间,我收到了一些错误消息。

代码:

private static final String TABLE_WIFI = "wifi"; // table name

private static final String KEY_BSSID = "bssid";
private static final String KEY_NAME = "name";
private static final String KEY_LAT = "lat";
private static final String KEY_LNG = "lng";
private static final String KEY_ACCURACY = "accuracy";

public void onCreate(SQLiteDatabase db)
{
String CREATE_WIFI_TABLE = "CREATE TABLE " + TABLE_WIFI + "("
+ KEY_BSSID + " TEXT," + KEY_NAME + " TEXT,"
+ KEY_LAT + " TEXT," + KEY_LNG + " TEXT," + KEY_ACCURACY + " TEXT" +")";
db.execSQL(CREATE_WIFI_TABLE);
}

public void updateLocation(Wifi theWifiLocation)
{
SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();
values.put(KEY_LAT, theWifiLocation.getLat());
values.put(KEY_LNG, theWifiLocation.getLng());
values.put(KEY_ACCURACY, theWifiLocation.getAccuracy());

db.update(TABLE_WIFI, values, KEY_BSSID + "=" + theWifiLocation.getBssid(), null);
}

错误日志:

04-26 22:35:42.334: E/AndroidRuntime(30194): FATAL EXCEPTION: Thread-4130
04-26 22:35:42.334: E/AndroidRuntime(30194): android.database.sqlite.SQLiteException: near ":04": syntax error: , while compiling: UPDATE wifi SET lng=?,accuracy=?,lat=? WHERE bssid=54:04:a6:de:98:0c
04-26 22:35:42.334: E/AndroidRuntime(30194): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
04-26 22:35:42.334: E/AndroidRuntime(30194): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
04-26 22:35:42.334: E/AndroidRuntime(30194): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:150)
04-26 22:35:42.334: E/AndroidRuntime(30194): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:368)
04-26 22:35:42.334: E/AndroidRuntime(30194): at android.database.sqlite.SQLiteStatement.acquireAndLock(SQLiteStatement.java:272)
04-26 22:35:42.334: E/AndroidRuntime(30194): at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:84)
04-26 22:35:42.334: E/AndroidRuntime(30194): at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1919)
04-26 22:35:42.334: E/AndroidRuntime(30194): at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1870)

谁能帮帮我

谢谢。

最佳答案

你的bsdid是一个String,所以你查询需要eiter

db.update(TABLE_WIFI, values, KEY_BSSID + "=\"" + theWifiLocation.getBssid() +"\"", null);

甚至更好

db.update(TABLE_WIFI, values, KEY_BSSID + "=?", new String[]{ theWifiLocation.getBssid() });

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

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