Java Spring:HSQL-无法执行数据库脚本

Java Spring:HSQL-无法执行数据库脚本,java,spring,hsqldb,spring-jdbc,Java,Spring,Hsqldb,Spring Jdbc,我试图使用以下两个脚本运行HSQL,然后对其进行测试,但每次都会出现无法处理的错误 无法执行数据库脚本;嵌套异常为org.springframework.jdbc.datasource.init.ScriptStatementFailedException:未能在资源类路径resource[data.SQL]的第4行执行SQL脚本语句:插入spittle(spitter_id,spittleText,postedTime)值(2,“试用Spring的新表达式语言”,“2010-06-11”) 更

我试图使用以下两个脚本运行HSQL,然后对其进行测试,但每次都会出现无法处理的错误

无法执行数据库脚本;嵌套异常为org.springframework.jdbc.datasource.init.ScriptStatementFailedException:未能在资源类路径resource[data.SQL]的第4行执行SQL脚本语句:插入spittle(spitter_id,spittleText,postedTime)值(2,“试用Spring的新表达式语言”,“2010-06-11”)

更新-引发的其他异常:

完整性约束冲突:外键无父项;系统FK_10108 桌子:唾沫

以下是我的脚本:

schema.sql

drop table if exists spittle;
drop table if exists spitter;

create table spitter (
  id identity,
  username varchar(25) not null,
  password varchar(25) not null,
  fullname varchar(100) not null,
  email varchar(50) not null,
  update_by_email boolean not null
);

create table spittle (
  id integer identity primary key,
  spitter_id integer not null,
  spittleText varchar(2000) not null,
  postedTime date not null,
  foreign key (spitter_id) references spitter(id)
);
data.sql

insert into spitter (username, password, fullname, email, update_by_email) values ('habuma', 'password', 'Craig Walls', 'craig@habuma.com', false);
insert into spitter (username, password, fullname, email, update_by_email) values ('artnames', 'password', 'Art Names', 'artnames@habuma.com', false);

insert into spittle (spitter_id, spittleText, postedTime) values (1, 'Have you read Spring in Action 3? I hear it is awesome!', '2010-06-09');
insert into spittle (spitter_id, spittleText, postedTime) values (2, 'Trying out Spring''s new expression language.', '2010-06-11');
insert into spittle (spitter_id, spittleText, postedTime) values (1, 'Who''s going to SpringOne/2GX this year?', '2010-06-19');
appContext.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <jdbc:embedded-database id="dataSource" type="H2">
        <jdbc:script location="classpath:schema.sql" />
        <jdbc:script location="classpath:data.sql" />
    </jdbc:embedded-database>

</beans>

脚本以0开始ID列值。可以指定起始值

create table spitter (
  id int generated by default as identity (start with 1) primary key,
  username varchar(25) not null,
  password varchar(25) not null,
  fullname varchar(100) not null,
  email varchar(50) not null,
  update_by_email boolean not null
);
或者,您可以显式插入ID:

insert into spitter (id, username, password, fullname, email, update_by_email) values (1, 'habuma', 'password', 'Craig Walls', 'craig@habuma.com', false);

@SotiriosDelimanolis Prepared语句如下所示
SQL\u SELECT\u SPITTER=“从SPITTER中选择id、username、fullname,其中id=?”
。但我测试了这个应用程序,但它在
setUp()
方法上失败了(其他方法也有评论)。@SotiriosDelimanolis你能说得更具体一点吗?我不确定我应该删除什么。我更新了问题,第二个例外是thas被抛出。@SotiriosDelimanolis它没有帮助。但是我刚刚注意到,在输出的末尾有
log4j:WARN,没有为logger(org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory)找到任何附加程序。log4j:WARN请正确初始化log4j系统。
这可能是我的问题的根源吗?不,这无关紧要。@SotiriosDelimanolis问题似乎在于
数据。sql
插入到
Spitle
表的行中。我测试了同一个脚本,没有插入到
spittle
,它可以工作。错误为
java.sql.SQLIntegrityConstraintViolationException:完整性约束冲突:外键无父项;SYS_FK_10108表格:Spitle
。我不确定,但剧本真的有问题吗?
insert into spitter (id, username, password, fullname, email, update_by_email) values (1, 'habuma', 'password', 'Craig Walls', 'craig@habuma.com', false);