为什么我得到SQLSyntaxErrorException - 遇到“”?

时间:2009-11-29 19:59:36

标签: java jdbc

此方法不断在标题中抛出异常,我找不到原因,我已通过连接创建了其他表,并且已创建所有引用的表。我正在使用嵌入式JavaDB

private void createEvidenceTable() throws SQLException
{
    Statement evidenceTable = CONNECTION.createStatement();
    evidenceTable.execute("CREATE TABLE evidence("+
                            "evidence_id INTEGER NOT NULL PRIMARY KEY,"+
                            "date_added VARCHAR(6) NOT NULL,"+
                            "evidence_dated VARCHAR(6) NOT NULL,"+
                            "evidence_file varchar(20),"+
                            "evidence_text VARCHAR(10),"+
                            "source_location_id INTEGER,"+
                            "source_person_id INTEGER,"+
                            "evidence_type VARCHAR(20),"+
"CONSTRAINT evidence__location_source FOREIGN KEY(source_location_id) REFERENCES location_source,"+
"CONSTRAINT evidence_person_source FOREIGN KEY(source_person_id) REFERENCES person_source,"+
"CONSTARINT evidence_evidence_type FOREIGN KEY(evidence_type) REFERENCES evidence_types)");

}

2 个答案:

答案 0 :(得分:5)

一个明确的问题是第三个约束子句拼写错误(CONSTARINT iso CONSTRAINT

答案 1 :(得分:0)

这适用于MySQL客户端:

CREATE TABLE evidence
(
    evidence_id INTEGER NOT NULL,
    date_added VARCHAR(6) NOT NULL, 
    evidence_dated VARCHAR(6) NOT NULL, 
    evidence_file varchar(20),
    evidence_text VARCHAR(10),
    source_location_id INTEGER,
    source_person_id INTEGER,
    evidence_type VARCHAR(20),
    PRIMARY KEY(evidence_id),
    FOREIGN KEY(source_location_id) REFERENCES location_source(source_location_id),
    FOREIGN KEY(source_person_id) REFERENCES person_source(source_person_id),
    FOREIGN KEY(evidence_type) REFERENCES evidence_types(evidence_type)
);

为什么要使用VARCHAR(6)而不是DATE?对我来说没什么意义。