Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在ApacheDerby中声明外键?_Java_Foreign Keys_Derby - Fatal编程技术网

Java 如何在ApacheDerby中声明外键?

Java 如何在ApacheDerby中声明外键?,java,foreign-keys,derby,Java,Foreign Keys,Derby,我现在正试着做一个R.D.B.,但外键好像没法用。运行程序时,会创建两个没有外键的表(Word和PDF),然后索引表中会出现运行时错误: 表“INDEX”包含列“WORDID”不在表中的约束定义。德比正常关闭 这是我的密码: new String createSQL3 = "create table Index (" + " IndexID integer not null generated always as" + &

我现在正试着做一个R.D.B.,但外键好像没法用。运行程序时,会创建两个没有外键的表(Word和PDF),然后索引表中会出现运行时错误:

表“INDEX”包含列“WORDID”不在表中的约束定义。德比正常关闭

这是我的密码:

new String createSQL3 = "create table Index (" 
        + " IndexID integer not null generated always as"
        + " identity (start with 1, increment by 1),"
        + " IndexPage integer not null, IndexOccurences integer not null,"
        + " constraint IndexID_PK primary key (IndexID),"
        + " constraint WordID_FK FOREIGN KEY (WordID) REFERENCES Words(WordID),"
        + " constraint PDFID_FK FOREIGN KEY (PDFID) REFERENCES PDFs(PDFID))";
            
        statement.execute(createSQL3);
        System.out.println("Table Index created successfully");
         
        connection.commit();
        
    } catch (SQLException EX) {
        System.out.println(EX.getMessage());

此语法:

constraint WordID_FK FOREIGN KEY (WordID) REFERENCES Words(WordID)
表示希望表
Index
中的列
WordID
引用表
Words
中的列
WordID

但是,正如消息所说,您没有在表
Index
中定义名为
WordID
的列。您的
索引
表只有三列:
IndexID
IndexPage
IndexOccurrences

你可能想要像这样的东西

WordID integer,
在表
索引的定义中,此语法:

constraint WordID_FK FOREIGN KEY (WordID) REFERENCES Words(WordID)
表示希望表
Index
中的列
WordID
引用表
Words
中的列
WordID

但是,正如消息所说,您没有在表
Index
中定义名为
WordID
的列。您的
索引
表只有三列:
IndexID
IndexPage
IndexOccurrences

你可能想要像这样的东西

WordID integer,
在表
索引的定义中