This is GUI
program in which when click the button it delete the row.But the problem is it give exception like this
Cannot delete or update a parent row: a foreign key constraint fails (`sakila`.`film_actor`, CONSTRAINT `fk_film_actor_actor` FOREIGN KEY (`actor_id`) REFERENCES `actor` (`actor_id`) ON UPDATE CASCADE)
I don't know what does it mean but i want to delete that row is there any way that work for this.
This is snap of schema and tables.
Code :
public class GUI extends JFrame {
public GUI() {
super("Frame");
setLayout(new FlowLayout());
JButton b1 = new JButton("Click Delete Row");
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/cinema", "hussnain", "toot");
String query = "delete from sakila.actor where actor_id=3";
PreparedStatement pre = conn.prepareStatement(query);
pre.executeUpdate();
JOptionPane.showMessageDialog(null, "Query Executed");
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, e1.getMessage());
e1.printStackTrace();
}
}
});
add(b1);
setSize(400, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
}
Main Method
public class Main {
public static void main(String[] args) {
GUI obj = new GUI();
}
}