Apache Derby - 语法错误:遇到“;”在第8栏第2栏

时间:2016-01-26 00:35:11

标签: java sql syntax-error derby javadb

在Java中创建一个小型模块化流程。但是,当我从我的网站调用SQL语句时,系统返回错误:

 java.sql.SQLSyntaxErrorException: Syntax error: Encountered ";" at line 8, column 2.

以下是有问题的SQL文件的前几行以及用于检索数据的系统。

SQL:

 CREATE TABLE "chat_logs"
 (
   "logId" BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "logDate" INT DEFAULT NULL,
   "logUser" BLOB,
   "logMessage" BLOB,
   PRIMARY KEY ("logId")
 );

 CREATE TABLE "configs"
 (
   "configId" BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "configType" BLOB,
   "configSettings" BLOB,
   PRIMARY KEY ("configId")
 );

 ...

检索脚本:

 InputStream in = new URL("http://db.*******.com/derby/version1.00.sql").openStream();
 return org.apache.commons.io.IOUtils.toString(in);

如何从一个分号应该出现的地方生成语法错误是没有意义的。

1 个答案:

答案 0 :(得分:3)

是的,您需要将字符串拆分为单独的语句并分别运行:

String[] createTableStatements = allStatements.Split...
for (String createStatement : createTableStatements) {
    try (Statement ps = connection.createStatement()) {
        ps.executeUpdate(createStatement);
    }
}