Rio Ablas :
Necesito ayuda con un proyecto final que estoy haciendo para la universidad, estoy haciendo una especie Biblioteca del Sistema. Soy nuevo en MySQL.
Estoy teniendo un problema en el código diciendo: "Índice de parámetro fuera de rango (3> número de parámetros, que es 2)."
PreparedStatement book_edit = book_db.prepareStatement("update books set ?='?' where id=?");
book_edit.setString(1, column); //where column is to set the column of the table
book_edit.setString(2, input); //where input is what you want to change
book_edit.setInt(3, book_id); //the primary key in my database
int i = book_edit.executeUpdate();
if (i != 0) {
System.out.println("UPDATED!!");
}
else {
System.out.println("Failed to Add Data!");
}
Eran :
El nombre de la columna no puede ser una variable de la PreparedStatement
. Debe ser parte del SQL String
:
PreparedStatement book_edit = book_db.prepareStatement("update books set " + column + "= ? where id = ?");
book_edit.setString(1, input); //where input is what you want to change
book_edit.setInt(2, book_id); //the primary key in my database