Santiago Bustamante Santiago Bustamante - 1 year ago 39
SQL Question

Error SQL syntax with query Java

I have this problem with Java using MySQL.

PreparedStatement paisyprovincia_BBDD = bd.prepareStatement("SELECT id=? FROM tabla=? WHERE ? = ?");

paisyprovincia_BBDD.setString(1, "id");
paisyprovincia_BBDD.setString(2, "pais");
paisyprovincia_BBDD.setString(3, "paisnombre");

Returns this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''pais' WHERE 'paisnombre' = 'Australia'' at line 1

where is the problem? thanks for the answers

Answer Source

Use this as your SQL statement:

bd.prepareStatement("SELECT id FROM pais WHERE paisnombre = ?");
paisyprovincia_BBDD.setString(1, country.getSelectionModel().getSelectedItem().toString());