Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
closed by

Is there any easiest 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

closed

4 Answers

0 votes
by (11.7k points)
selected by
 
Best answer

You can try a bit more generalized script to start the databases.

Steps:

  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

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

If you want to get more insights of SQL, checkout this SQL Course from Intellipaat.

0 votes
by (13k points)

To create several HSQLDB server databases, you can follow the steps below:

1. Create separate folders for each database:

   Before starting, create separate folders to store the database files. For example:

   - /opt/db/trunk

   - /opt/db/master

2. Create a shell script to start the databases:

   Create a file named "start.sh" and add the following content:

#!/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

This script uses the `org.hsqldb.server.Server` class to start the HSQLDB server with two databases. Adjust the file paths and database names according to your setup.

3. Make the script executable:

   Run the following command to make the script executable:

chmod +x start.sh

4. Start the databases:

   Execute the script using the following command:

./start.sh

You should see output similar to the following:

...

[Server@15c7850]: Database [index=0, id=0, db=file:/opt/db/trunk/trunk, alias=trunk] opened successfully in 426 ms.

[Server@15c7850]: Database [index=1, id=1, db=file:/opt/db/master/master, alias=master] opened successfully in 128 ms.

[Server@15c7850]: From command line, use [Ctrl]+[C] to abort abruptly

The script will start the HSQLDB server with the specified databases and aliases (trunk and master in this example).

To configure the HSQL Database Manager, use the following details:

- Type: HSQL Database engine server

- Driver: org.hsqldb.jdbcDriver

- URL: jdbc:hsqldb:hsql://localhost:9001/trunk (or jdbc:hsqldb:hsql://localhost:9001/master for the master database)

- User: SA

- Password: (leave blank)

You can change the alias "trunk" to another alias if desired.

The JDBC URL connections for the databases will be:

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

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

0 votes
by (11.4k points)
Certainly! Here's a more generalized script to start multiple HSQLDB server databases:

#!/bin/sh

start_string="java -cp ./hsqldb/lib/hsqldb.jar org.hsqldb.server.Server"

parent_folder=$1

counter=0

# Create database folders if they don't exist

shift

while [ $# -gt 0 ]

do

  db_name=$1

  db_folder=$parent_folder/$db_name

  

  if [ ! -d "$db_folder" ]; then

    mkdir -p "$db_folder"

  fi

  

  start_string="$start_string --database.$counter file:$db_folder/$db_name --dbname.$counter $db_name"

  

  shift

  counter=$((counter+1))

done

# Start the databases

eval $start_string

Here's how you can use this script:

Save the script into a file, e.g., start_databases.sh.

Make the script executable: chmod +x start_databases.sh.

Execute the script, providing the parent folder path and the names of the databases as parameters. For example:

./start_databases.sh /opt/db/ trunk master anotherdb

This will create folders /opt/db/trunk, /opt/db/master, and /opt/db/anotherdb if they don't exist. It will then start the HSQLDB server with these databases and aliases. You can adjust the parent folder and database names as needed.
0 votes
by (7.8k points)
#!/bin/sh

start_string="java -cp ./hsqldb/lib/hsqldb.jar org.hsqldb.server.Server"

parent_folder="$1"

counter=0

shift

for db_name in "$@"

do

  db_folder="$parent_folder/$db_name"

  if [ ! -d "$db_folder" ]; then

    mkdir -p "$db_folder"

  fi

  start_string="$start_string --database.$counter file:$db_folder/$db_name --dbname.$counter $db_name"

  

  counter=$((counter+1))

done

eval "$start_string"

Here's how you can use this script:

Save the script into a file, e.g., start_databases.sh.

Make the script executable: chmod +x start_databases.sh.

Execute the script, providing the parent folder path and the names of the databases as parameters. For example:

./start_databases.sh /opt/db/ trunk master anotherdb

This script will create folders /opt/db/trunk, /opt/db/master, and /opt/db/anotherdb if they don't already exist. It will then start the HSQLDB server with these databases and respective aliases. You can adjust the parent folder and database names as per your requirements.

Remember to replace /opt/db/ with the desired parent folder path, and specify the database names you want to create.

Browse Categories

...