简体   繁体   中英

Updating SQLite - near “WHERE”: syntax error (code 1 SQLITE_ERROR):

I recently added a column to my SQLite database, since adding this column a button which I had which sets the value of one of the database columns to "1" or "0" have now started to crash my application when the button tries to use the updateData(), so I assume thats where my issue is, is in the code or the syntax of the updateData()

Error:

android.database.sqlite.SQLiteException: near "WHERE": syntax error (code 1 SQLITE_ERROR): , while compiling: UPDATE my_manager SET location_name = 'blarney stone', location_county = 'Cork',location_description = 'jj',location_route = '1',location_position = '2',location_longg = 'null',location_lat = 'null',location_url = 'JJ',location_url2 = 'jj',location_url3 = 'jj', WHERE location_id = '1' at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)

Code:

 void updateData(String id, String row_id, String name, String county, String description, String 
  in_route, String position, String lat, String longg, String url, String url2, String url3) {
    System.out.println(TABLE_NAME+"; "+row_id +"; "+ name +"; "+ county+"; "+ description+"; " + lat 
   +"; "+ longg+"; "+ url +"; "+ url2 +"; "+ url3 +"; ");
    SQLiteDatabase db = this.getReadableDatabase();
    db.execSQL("UPDATE " + "my_manager" + " SET location_name = "+"'"+ name + "' " + ", " +
            "location_county = " + "'"+ county + "'"+ "," +
            "location_description = " + "'"+ description +  "'" + "," +
            "location_route = " + "'"+ in_route +  "'" + "," +
            "location_position = " + "'"+ position +  "'" + "," +
            "location_longg = " + "'"+ longg +  "'" + "," +
            "location_lat = " + "'"+ lat +  "'" + "," +
            "location_url = " + "'"+ url +  "'" + "," +
            "location_url2 = " + "'"+ url2 +  "'" + "," +
            "location_url3 = " + "'"+ url3 +  "'" + "," + " WHERE location_id = "+"'"+ row_id+"'");

Sorry my friend don't take this as a bad but how about you avoid to much unnecessary "+" if it is possible.

void updateData("UPDATE my_manager SET location_name = '"+ name + "', " +
            "location_county = '"+ county + "', " +
            "location_description = '"+ description +  "'," +
            "location_route = '"+ in_route +  "', " +
            "location_position = '" + position + "', " +
            "location_longg = '" + longg + "'," +
            "location_lat = '" + lat +  "'," +
            "location_url = '" + url +  "', " +
            "location_url2 = '"+ url2 +  "', " +
            "location_url3 = '"+ url3 +  "' WHERE location_id = '"+ row_id+"'");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM