Problems updating sqlite for Android

I apologize if my question is too simple and will explain to me what happened in my update request.

I have sqlite to store my records in an android application. I was able to insert and select successfully. However, during the update, I get some error.

The code:

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);
    }

Error Log:

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)

Can anybody help me

Thank.

+5
source share
1 answer

Your bsdid is a string, so you need to execute eiter

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

or even better

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

All Articles