Good, I'm doing a program to add / remove / modify artists from a database and when I try to delete the artist I skip this:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Can not delete or update a parent row: a foreign key constraint fails (
chinook
.album
, CONSTRAINTFK_AlbumArtistId
FOREIGN KEY (ArtistId
) REFERENCESartist
(ArtistId
) ON DELETE NO ACTION ON UPDATE NO ACTION) at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance (Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (Unknown Source) at java.lang.reflect.Constructor.newInstance (Unknown Source) at com.mysql.jdbc.Util.handleNewInstance (Util.java:404) at com.mysql.jdbc.Util.getInstance (Util.java:387) at com.mysql.jdbc.SQLError.createSQLException (SQLError.java:932) at com.mysql.jdbc.MysqlIO.checkErrorPacket (MysqlIO.java:3878) at com.mysql.jdbc.MysqlIO.checkErrorPacket (MysqlIO.java:3814) at com.mysql.jdbc.MysqlIO.sendCommand (MysqlIO.java:2478) at com.mysql.jdbc.MysqlIO.sqlQueryDirect (MysqlIO.java:2625) at com.mysql.jdbc.ConnectionImpl.execSQL (ConnectionImpl.java:2551) at com.mysql.jdbc.PreparedStatement.executeInternal (PreparedStatement.java:1861) at com.mysql.jdbc.PreparedStatement.executeUpdateInternal (PreparedStatement.java:2073) at com.mysql.jdbc.PreparedStatement.executeUpdateInternal (PreparedStatement.java:2009) at com.mysql.jdbc.PreparedStatement.executeLargeUpdate (PreparedStatement.java:5094) at com.mysql.jdbc.PreparedStatement.executeUpdate (PreparedStatement.java:1994) at modelo.dao.ArtistaDAO.eliminarArtista (ArtistDAO.java:103) at vista.VistaArtistasSearch.actionPerformed (VistaArtistasSearch.java:164) at javax.swing.AbstractButton.fireActionPerformed (Unknown Source) at javax.swing.AbstractButton $ Handler.actionPerformed (Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source) at javax.swing.DefaultButtonModel.setPressed (Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased (Unknown Source) at java.awt.Component.processMouseEvent (Unknown Source) at javax.swing.JComponent.processMouseEvent (Unknown Source) at java.awt.Component.processEvent (Unknown Source) at java.awt.Container.processEvent (Unknown Source) at java.awt.Component.dispatchEventImpl (Unknown Source) at java.awt.Container.dispatchEventImpl (Unknown Source) at java.awt.Component.dispatchEvent (Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent (Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent (Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent (Unknown Source) at java.awt.Container.dispatchEventImpl (Unknown Source) at java.awt.Window.dispatchEventImpl (Unknown Source) at java.awt.Component.dispatchEvent (Unknown Source) at java.awt.EventQueue.dispatchEventImpl (Unknown Source) at java.awt.EventQueue.access $ 500 (Unknown Source) at java.awt.EventQueue $ 3.run (Unknown Source) at java.awt.EventQueue $ 3.run (Unknown Source) at java.security.AccessController.doPrivileged (Native Method) at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege (Unknown Source) at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege (Unknown Source) at java.awt.EventQueue $ 4.run (Unknown Source) at java.awt.EventQueue $ 4.run (Unknown Source) at java.security.AccessController.doPrivileged (Native Method) at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege (Unknown Source) at java.awt.EventQueue.dispatchEvent (Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters (Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter (Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy (Unknown Source) at java.awt.EventDispatchThread.pumpEvents (Unknown Source) at java.awt.EventDispatchThread.pumpEvents (Unknown Source) at java.awt.EventDispatchThread.run (Unknown Source)
I think I know what the problem is, and that I should do on delete cascade
, but I do not know how to do it so that the program executes it only once, since I can not make changes in the database itself, everything must be through the program.