DB2 SQL-Erreur: -803 lors de l'insertion dans deux tables liées

J'ai deux tables qui sont créés avec cette déclaration:

CREATE TABLE Behandlungsvorgang (
 patientId SMALLINT NOT NULL REFERENCES Patient(id),
 datum DATE NOT NULL,
 notizen VARCHAR(100),
 PRIMARY KEY (patientId, datum)
);

CREATE TABLE behandelt (
 arztLogin VARCHAR(50) NOT NULL REFERENCES Arzt(login),
 behandlungsDatum DATE NOT NULL,
 behandlungsPatientId SMALLINT NOT NULL,
 medikamntPzn SMALLINT NOT NULL REFERENCES Medikament(pzn),
 krankheitName VARCHAR(50) NOT NULL REFERENCES Krankheit(name),
 PRIMARY KEY (arztLogin, behandlungsDatum, behandlungsPatientId, medikamntPzn, krankheitName),
 FOREIGN KEY (behandlungsDatum, behandlungsPatientId) REFERENCES Behandlungsvorgang(datum, patientId)
);

Et j'ai une méthode qui devrait insérer des données dans ce tableau. Il a toujours insère de nouvelles données avant de les insérer dans behandelt j'ai insérer dans Behandlungsvorgang pour s'acquitter de la clé étrangère exigences. La méthode ressemble à ceci:

public void add(TreatmentProcess tp) throws StoreException {
    try {
        PreparedStatement psBehandlungsvorgang = connection.prepareStatement("INSERT INTO Behandlungsvorgang (patientId, datum, notizen) VALUES (?, ?, ?)");
        psBehandlungsvorgang.setInt(1, tp.getPatientId());
        psBehandlungsvorgang.setDate(2, tp.getDate());
        psBehandlungsvorgang.setString(3, tp.getNotes());

        psBehandlungsvorgang.executeUpdate();

        PreparedStatement psBehandelt = connection.prepareStatement("INSERT INTO behandelt (arztLogin, behandlungsDatum, behandlungsPatientId, medikamntPzn, krankheitName) VALUES (?, ?, ?, ?, ?)");

        for (Drug drug : tp.getDrugs()) {
            psBehandelt.setString(1, tp.getDoctor());
            psBehandelt.setDate(2, tp.getDate());
            psBehandelt.setInt(3, tp.getPatientId());
            psBehandelt.setInt(4, drug.getPzn());
            psBehandelt.setString(5, tp.getDisease());
            psBehandelt.addBatch();
        }

        psBehandelt.executeBatch();
    } catch (SQLException e) {
        throw new StoreException(e);
    } 
}

Je reçois toujours une exception en disant de.unidue.inf.is.stores.StoreException: com.ibm.db2.jcc.am.go: DB2 SQL Error: SQLCODE=-803, SQLSTATE=23505, SQLERRMC=1;DBP10.BEHANDLUNGSVORGANG, DRIVER=4.7.85. Si j'insère les données manuellement je n'obtiens pas d'erreurs. Par exemple:

insert into Behandlungsvorgang values (1, '2014-01-25', 'Test');
insert into behandelt values ('doc', '2014-01-25', 1, 1, 'Kater');
insert into behandelt values ('doc', '2014-01-25', 1, 2, 'Kater');

Ce que je fais mal dans le code java?

Cette question est généralement bien écrit; vous liste l'erreur que vous obtenez (même si n'avez pas de liste de ce que le code donne), la définition de la table, votre code, si +1,..., malheureusement, compte tenu de la réponse que vous avez posté, cela devrait sans doute être fermé comme une erreur typographique. (Vous n'avez pas de réel problème dans votre code, après tout)

OriginalL'auteur stevecross | 2014-01-31