jeudi 4 juin 2015

DB2, Java: Can not CREATE TABLE conditionally

I'm trying to create a table within an IF-THEN-ELSE statement in Java. Here is what i've tried so far:

stmt.execute(
                "BEGIN IF (SELECT tabname FROM syscat.tables WHERE tabname = 'KUNDENKONTAKTDATEN' and tabschema = 'GRP35') IS NULL THEN "
                + "CREATE TABLE KundenKontaktDaten(Kunden_Nr INT NOT NULL PRIMARY KEY, Twitter_Id VARCHAR(40), Google_Id BIGINT, Facebook_Id BIGINT, Skype_Id VARCHAR(64), Telefonnummer VARCHAR(50));"
                + "ELSE "
                + "DELETE FROM KundenKontaktDaten; "
                + "END IF;"
                + "END");

Running this one i always get the following exception:

DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=KEY;INT NOT NULL PRIMARY;<references_spec>, DRIVER=4.13.80

Removing NOT NULL and PRIMARY KEY from Kunden_Nr returns the following exception:

DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=<ddl-statement>, DRIVER=4.13.80

Does anyone has any idea how to handle that one?

greets

Aucun commentaire:

Enregistrer un commentaire