如何在没有程序冻结的情况下删除级联的表记录?
这是我的删除按钮方法,它将大学名称作为主键并删除,以便整个记录被删除。但是,它无法删除,因为该表大学是学生表和部门桌的家长表。我想在级联上删除,但是当我单击它时,按钮会冻结,但是如果放下外国钥匙,它可以很好地工作。总而言之,我想在级联删除记录,而不会在Jframe中遇到任何麻烦。
大学桌

private void deleteActionPerformed(java.awt.event.ActionEvent evt) {
try{
String sql = " DELETE FROM college where college_name = ?";
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","moe");
pst = conn.prepareStatement(sql);
pst.setString(1,college_name.getText());
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "deleted successfully");
}
catch (Exception ex) {
JOptionPane.showMessageDialog(null,ex);
}
showData();
}
this is my delete button method, it takes the college name as a primary key and deletes it so the whole record gets deleted. However, it can't be deleted because this table COLLEGE is the parent table for the STUDENTS table and DEPARTMENT table. I want to delete on cascade but the button freezes when I click it but if I drop the foreign keys it works pretty well. To sum up, I want to delete the record on cascade without having any trouble in the JFrame.
College table
private void deleteActionPerformed(java.awt.event.ActionEvent evt) {
try{
String sql = " DELETE FROM college where college_name = ?";
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","moe");
pst = conn.prepareStatement(sql);
pst.setString(1,college_name.getText());
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "deleted successfully");
}
catch (Exception ex) {
JOptionPane.showMessageDialog(null,ex);
}
showData();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论