What is the easiest way to create multiple HSQLDB server databases?

Is there an easier way? To run many databases, we can create a simple file "start.sh"

Before using, create separate folders for each database.

/ Opt / db / trunk

/ Opt / db / master

The following copy in "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 executable:

 chmod +x start.sh 

Beginning of work:

 $ ./hsqdb.sh 

Conclusion:

 ... [ 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 HSQL database manager settings:

Type: HSQL Database Server Server

Driver: org.hsqldb.jdbcDriver

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

User: SA

Password:

You can change the alias connecting line to another alias

Connection to JDBC URL:

JDBC: HSQLDB: HSQL: // local: 9001 / Trunk

JDBC: HSQLDB: HSQL: // local: 9001 / master

+6
source share
1 answer

You can write a more generalized script to start the database.

Some thoughts on the steps the script should execute

  • accept parameter list
  • declare start_string . initialize with java -cp ./hsqldb/lib/hsqldb.jar org.hsqldb.server.Server
  • The first parameter may be the path to the folder containing the folders for each database (for example, /opt/db/ )
    • all parameters after the first are considered database names
  • iterate over all database names and create a DB folder in the parent folder (1st parameter), if it does not already exist
    • add --database.<counter_variable> file:<parent_folder>/<db_name>/<db_name> --dbname.<counter_variable> <db_name> to start_string
  • execute start_string

Then you can transfer the list of database names to your program that will connect to them using the URL: jdbc:hsqldb:hsql://localhost:9001/<db_name>

+1
source

Source: https://habr.com/ru/post/919672/


All Articles