我正在努力寻找我在查询中做错的事情。我没有创建数据库,但这是结构: 4 Q$ s7 q, b: m" b3张桌子: $ c3 i Q0 A {+ `$ l车辆 :品牌、电机、价格、名称ID 2 m1 `* T, M- C' E选项 :id,描述,价格: r2 }1 y2 E* f0 M% ~ vehicule_option :id_vehicule,id_option' ~8 e! T) o, p4 E; q
我猜vehicule_option有两个外键,但我找不到添加的问题。这是我的代码,第一部分工作正常: " A9 l ^* A) D9 x5 G# \& M" o.getId() ");"; try Statement state = this.connect.createStatement();;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ResultSet rs = state.executeQuery(query); catch (SQLException e) e.printStackTrace(); return true; }" o.getId() ");"; } try{ Statement state = this.connect.createStatement(); ResultSet rs = state.executeQuery(query); } catch (SQLException e){ e.printStackTrace(); } return true; }因此,我在这里所做的基本上是在正确的列中插入两个值。它给了我以下异常:1 u8 t+ }' C! D' a* I' O
java.sql.SQLIntegrityConstraintViolationException: integrity constraint violation: foreign key no parent; SYS_FK_10132 table: VEHICULE_OPTION at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source) at org.hsqldb.jdbc.JDBCStatement.executeQuery(Unknown Source) at fr.ocr.sql.DAOVehicule.create(DAOVehicule.java:35) at fr.ocr.ihm.AddCarDialogBox$1.actionPerformed(AddCarDialogBox.java:151) 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$1.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$1.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$1.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)Caused by: org.hsqldb.HsqlException: integrity constraint violation: foreign key no parent; SYS_FK_10132 table: VEHICULE_OPTION at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.Constraint.getException(Unknown Source) at org.hsqldb.Constraint.checkInsert(Unknown Source) at org.hsqldb.StatementDML.performIntegrityChecks(Unknown Source) at org.hsqldb.StatementDML.insertSingleRow(Unknown Source) at org.hsqldb.StatementInsert.getResult(Unknown Source) at org.hsqldb.StatementDMQL.execute(Unknown Source) at org.hsqldb.Session.executeCompiledStatement(Unknown Source) at org.hsqldb.Session.executeDirectStatement(Unknown Source) at org.hsqldb.Session.execute(Unknown Source) ... 40 more n0 l; y; E( C' D" @解决方案: