I am trying to remove a record from the database with the book code I pick up from a combo and from all its associated data tables using PrepareStatement
but it is throwing me an error. I pass the code to you because surely it is not doing something correctly.
private void OnEliminarLibro(ActionEvent e) {
String aux= getRoot().getCodigoLibroEliminadosCombo().getSelectionModel().getSelectedItem();
PreparedStatement stmtLibrosAutores = null;
PreparedStatement stmtLibros = null;
PreparedStatement stmtEjemplares = null;
String consultaLibrosAutores = "DELETE codLibro FROM librosautores WHERE codLibro = ?";
String consultaEjemplares = "DELETE codLibro FROM ejemplares WHERE codLibro = ?";
String consultaLibros = "DELETE codLibro FROM libros WHERE codLibro = ?";
try {
stmtLibros = con.getCon().prepareStatement(consultaLibros);
int result = Integer.valueOf(aux);
System.out.println(result);
stmtLibros.setInt(1,result);
stmtLibros.executeUpdate();
stmtLibrosAutores = con.getCon().prepareStatement(consultaLibrosAutores);
stmtLibrosAutores.setInt(1, result);
stmtLibrosAutores.executeUpdate();
stmtEjemplares = con.getCon().prepareStatement(consultaEjemplares);
stmtEjemplares.setInt(1, result);
stmtEjemplares.executeUpdate();
System.out.println("Eliminacion realizada");
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
The trace of the error that you are giving me is the following:
Below I also attach an image of the structure of the Database as a reference.