When doing an update to a bd using java, I get this error:
I have checked the code carefully and can not detect the error by which it appears to me: paramenter index out of range 1
When doing an update to a bd using java, I get this error:
I have checked the code carefully and can not detect the error by which it appears to me: paramenter index out of range 1
Your error is due to the fact that you are declaring the query without parameters, since you are concatenating the values you want to set to each field within the same query: "NombreBanco='" + txtBanco.getText() + "', "
. If you do it in this way, which is not the recommended one, it would be wrong to then try to pass values to the parameters, since they do not exist. The correct way to do what you want would be: "NombreBanco = ?,"
.
For example:
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE Colaborador set nombre=? , apellidos=?");
preparedStatement.setString(1, txtNombre.getText());
preparedStatement.setString(2, txtApellidos.getText());