Search code examples
javamysqljdbcmysql-error-1054

Unknown column '' in 'where clause' while using variable for SET value


String SQL_UPDATE = "UPDATE `club_juvenil` SET "+SET_MySQL+" = "+nuevo_valor.getText().toString()+" WHERE dni_competidor = "+wher_combo.getSelectedItem().toString()+" ";

Hi. I'm trying to update a table on MySQL using Java, but I get the error Unknown column '(value from wher_combo)' in 'where clause' I'm trying to use a variable in the SET value to switch from one to other column(which is the main reason I decided to do it this way), but then the WHERE seems like it is reading the wher_combo value as a column, and obviously lends to an error because that column doesn't exist on the table.


Solution

  • It looks like you forgot quote. Like this, can you try ? :

    " WHERE dni_competidor = '"+wher_combo.getSelectedItem().toString()+"' ";