Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the simplest way to create several HSQLDB server databases? [closed]

Is there a simpler way? To start many database we can create simple file "start.sh"

Before start to use create separate folders for each databases.

/opt/db/trunk

/opt/db/master

Next one copy to "start.sh":

#!/bin/sh
java -cp ./hsqldb/lib/hsqldb.jar  org.hsqldb.server.Server --database.0 file:/opt/db/master/master --dbname.0 master --database.1 file:/opt/db/trunk/trunk --dbname.1 trunk

Make this file to be executable:

chmod +x start.sh

Start to run:

$ ./hsqdb.sh

Output:

...
[Server@15c7850]: Database [index=0, id=0, db=file:/opt/db/trunk/trunk, alias=trunk] opened sucessfully in 426 ms.
[Server@15c7850]: Database [index=1, id=1, db=file:/opt/db/master/master, alias=master] opened sucessfully in 128 ms.
...
[Server@15c7850]: From command line, use [Ctrl]+[C] to abort abruptly

So you will get two databases with aliases: trunk and master

Example how to configure HSQL Database Manager:

Type: HSQL Database engine server

Driver: org.hsqldb.jdbcDriver

URL: jdbc:hsqldb:hsql://localhost:9001/trunk

User: SA

Password:

You can change the alias trunk to another alias

JDBC URL connection:

jdbc:hsqldb:hsql://localhost:9001/trunk

jdbc:hsqldb:hsql://localhost:9001/master

like image 669
Veniamin Avatar asked Jul 04 '12 12:07

Veniamin


People also ask

What is HSQLDB in-memory database?

HSQLDB (HyperSQL Database) HSQLDB is an open source project, also written in Java, representing a relational database. It follows the SQL and JDBC standards and supports SQL features such as stored procedures and triggers. It can be used in the in-memory mode, or it can be configured to use disk storage.


1 Answers

You could write a more generalized script to start the databases.

Some thoughts on the steps the script would have to do

  1. accept a list of parameters
  2. declare start_string. initialize with java -cp ./hsqldb/lib/hsqldb.jar org.hsqldb.server.Server
  3. first parameter could be the path of the folder that contains the folders for each DB (e.g. /opt/db/)
    • all parameters after first are considered as DB names
  4. iterate over all DB names and create DB folder in parent folder (1st param) if it does not already exist
    • append --database.<counter_variable> file:<parent_folder>/<db_name>/<db_name> --dbname.<counter_variable> <db_name> to start_string
  5. execute start_string

You can then pass the list of DB names to your program, which will connect to them using URL: jdbc:hsqldb:hsql://localhost:9001/<db_name>

like image 194
hage Avatar answered Oct 19 '22 17:10

hage