开发者

Why am I getting SQLSyntaxErrorException - encountered ""?

This method keeps throwing the exception in the title, and I cannot find a reason, I have created other tables through the co开发者_高级运维nnection and all the referenced tables have been created. I'm using embedded 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)");

}


One definite problem is that the third constraint clause is misspelled (CONSTARINT iso CONSTRAINT)


This worked in MySQL client:

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)
);

Why would you use VARCHAR(6) instead of DATE? Makes little sense to me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜