5

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

我有 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)

谁能帮帮我吗

谢谢你。

4

1 回答 1

5

你的 bsdid 是一个字符串,所以你查询需要eiter

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

甚至更好

db.update(TABLE_WIFI, values, KEY_BSSID + "=?", new String[]{ theWifiLocation.getBssid() });
于 2013-04-26T17:33:17.350 回答