连接 HSQLDB 服务器

Connect HSQLDB Server

我想通过像 squirrel 这样的客户端连接我的 hsqldb。在我在内存中使用 hsqldb 之前,为了具有与另一个客户端连接的功能,我现在想使用服务器。但我坚持连接它。

我目前拥有的:

我将 hsqldb 启动为 Spring-Boot-Application:

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class ApplicationInfra {
    public static void main(final String[] args) {
        final ConfigurableApplicationContext context = SpringApplication.run(ApplicationInfra.class, args);

        final HyperSqlDbServer dbServer = context.getBean(HyperSqlDbServer.class);
        dbServer.displayInfo();

        try (final Scanner sc = new Scanner(System.in)) {
            do {
                System.out.println("Shutdown HSQLDB?[Y/N]: ");
            } while (sc.hasNext() && (!sc.next().equalsIgnoreCase("y")));
        }

        // =============================================================

        // SHUTDOWN DATABASE ...
        final DataSource dataSource = context.getBean(DataSource.class);
        final JdbcTemplate template = new JdbcTemplate(dataSource);
        template.execute("SHUTDOWN");

        context.close();
    }
}

我的 HyperSqlDbServer class:

@Configuration
public class HyperSqlDbServer implements SmartLifecycle {
    private final Logger logger = LoggerFactory.getLogger(HyperSqlDbServer.class);
    private HsqlProperties properties;
    private Server server;
    private boolean running = false;

    public HyperSqlDbServer() {
        final Properties props = new Properties();
        props.setProperty("server.database.0", "file:./hsqldb/bbsng");
        props.setProperty("server.dbname.0", "bbsng");
        props.setProperty("server.remote_open", "true");
        props.setProperty("server.trace", "true");
        props.setProperty("hsqldb.reconfig_logging", "false");
        properties = new HsqlProperties(props);
    }

    @Override
    public boolean isRunning() {
        if (server != null)
            server.checkRunning(running);
        return running;
    }

    @Override
    public void start() {
        if (server == null) {
            logger.info("Starting HSQL server...");
            server = new Server();
            try {
                server.setProperties(properties);
                server.start();
                running = true;
            } catch (AclFormatException afe) {
                logger.error("Error starting HSQL server.", afe);
            } catch (IOException e) {
                logger.error("Error starting HSQL server.", e);
            }
        }
    }

    @Override
    public void stop() {
        logger.info("Stopping HSQL server...");
        if (server != null) {
            server.stop();
            running = false;
        }
    }

    @Override
    public int getPhase() {
        return 0;
    }

    @Override
    public boolean isAutoStartup() {
        return true;
    }

    @Override
    public void stop(Runnable runnable) {
        stop();
        runnable.run();
    }

}

我的应用程序属性

# DATA-SOURCE CONFIGURATION:
spring.datasource.url=jdbc\:hsqldb\:bbsng
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.hsqldb.jdbcDriver

spring.jpa.hibernate.ddl-auto=create
spring.jpa.hibernate.dialect=org.hibernate.dialect.HSQLDialect
spring.jpa.show-sql=true

控制台显示休眠创建了新的 tables:

Hibernate: create table apprentice (id bigint not null, city varchar(255), street varchar(255), street_number varchar(255), urban_district varchar(255), zip varchar(255), email varchar(255), fax varchar(255), mobile varchar(255), phone varchar(255), first_name varchar(255) not null, last_name varchar(255) not null, version integer, rural_district bigint, primary key (id))
Hibernate: create table company (id bigint not null, city varchar(255), street varchar(255), street_number varchar(255), urban_district varchar(255), zip varchar(255), email varchar(255), fax varchar(255), mobile varchar(255), phone varchar(255), name varchar(255) not null, number varchar(255) not null, version integer, rural_district bigint, primary key (id))
Hibernate: create table company_occupation_combination (id bigint not null, version integer, company bigint not null, occupation_combination bigint not null, primary key (id))
Hibernate: create table contract (id bigint not null, education_end date not null, education_start date not null, status integer not null, version integer, apprentice bigint not null, company_occupation_combination bigint not null, office bigint not null, primary key (id))
Hibernate: create table district (id bigint not null, name varchar(255) not null, version integer, primary key (id))

...

并且 HSQLDB 服务器已启动:

2015-12-28 21:20:24.765  INFO 9832 --- [           main] at.compax.bbsng.infra.HyperSqlDbServer   : Starting HSQL server...
[Server@35c9a231]: [Thread[main,5,main]]: checkRunning(false) entered
[Server@35c9a231]: [Thread[main,5,main]]: checkRunning(false) exited
[Server@35c9a231]: Initiating startup sequence...
[Server@35c9a231]: Server socket opened successfully in 0 ms.
[Server@35c9a231]: Database [index=0, id=1, db=file:./hsqldb/bbsng, alias=bbsng] opened sucessfully in 40 ms.
[Server@35c9a231]: Startup sequence completed in 50 ms.
[Server@35c9a231]: 2015-12-28 21:20:24.815 HSQLDB server 2.3.3 is online on port 9001
[Server@35c9a231]: To close normally, connect and execute SHUTDOWN SQL
[Server@35c9a231]: From command line, use [Ctrl]+[C] to abort abruptly

但是我找不到table有松鼠的! 我的配置如下:

你只需要将你的问题写到Whosebug,你就会看到你自己的错误。

我的数据源不正确,hibernate 在另一个创建的数据库中添加了表。解决方案是在 application.properties:

中修复
spring.datasource.url=jdbc\:hsqldb\:file\:./hsqldb/bbsng