0
我想通過像松鼠這樣的客戶端連接我的hsqldb。在內存中使用hsqldb之前,爲了讓該功能與另一個客戶端連接,我現在想要使用服務器。但我正在連接它。連接HSQLDB服務器
我到目前爲止有:
我開始HSQLDB作爲彈簧開機應用:
@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類:
@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
控制檯說,休眠創建新表:
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...
[[email protected]]: [Thread[main,5,main]]: checkRunning(false) entered
[[email protected]]: [Thread[main,5,main]]: checkRunning(false) exited
[[email protected]]: Initiating startup sequence...
[[email protected]]: Server socket opened successfully in 0 ms.
[[email protected]]: Database [index=0, id=1, db=file:./hsqldb/bbsng, alias=bbsng] opened sucessfully in 40 ms.
[[email protected]]: Startup sequence completed in 50 ms.
[[email protected]]: 2015-12-28 21:20:24.815 HSQLDB server 2.3.3 is online on port 9001
[[email protected]]: To close normally, connect and execute SHUTDOWN SQL
[[email protected]]: From command line, use [Ctrl]+[C] to abort abruptly
,但我不能找到表與松鼠! 我的配置是這樣的: