HSQLDB Manage a new standalone database with ant [

2019-07-27 16:04发布

I'm planning to use HSQLDB, I'm trying an example with ant.

the build file:

<target name="create.tables">
  <echo>Creating tables using: ${db.driver} ${db.url}</echo>
  <sql driver="${db.driver}"
      url="${db.url}"
      userid="${db.username}"
      password="${db.password}"
      onerror="continue"
      src="hsqldb/create_cars.sql">
      <classpath refid="hsqldb.database" />
  </sql>
</target>

<target name="load.data">
  <echo>Load Data Using: ${db.driver} ${db.url}</echo>
  <sql  driver="${db.driver}"
      url="${db.url}"
      userid="${db.username}"
      password="${db.password}"
      onerror="continue"
      src="hsqldb/load_data.sql">
      <classpath refid="hsqldb.database" />
  </sql>
</target>

properties:

db.driver=org.hsqldb.jdbcDriver
db.url=jdbc:hsqldb:file:hsqldb/dbcars
db.username=sa
db.password=

create_tables.sql:

CREATE TABLE cars (
     id INTEGER NOT NULL PRIMARY KEY,
     description VARCHAR(255)
) ;

load_data.sql:

INSERT INTO cars (id, description) VALUES (1, 'first car') ;
INSERT INTO cars (id, description) VALUES (2, 'second car') ;

the create.tables target works, but load.data give this error:

[sql] java.sql.SQLException: Table not found in statement [ SELECT * FROM cars]

标签: ant hsqldb
1条回答
We Are One
2楼-- · 2019-07-27 16:25

Usually this is caused by a short duration connection to the database. The table definition is not persisted and cannot be found later. See the list of connection properties you can use:

http://www.hsqldb.org/doc/2.0/guide/dbproperties-chapt.html

Then try this:

db.driver=org.hsqldb.jdbcDriver
db.url=jdbc:hsqldb:file:hsqldb/dbcars;shutdown=true
db.username=sa
db.password=

If it doesn't work, try this:

db.driver=org.hsqldb.jdbcDriver
db.url=jdbc:hsqldb:file:hsqldb/dbcars;hsqldb.write_delay=false
db.username=sa
db.password=
查看更多
登录 后发表回答