# H2 Database Server Setup

# Summary

To improve the performance of the calendar dashboard page, incident information is cached in an H2 database. Whenever the yCrash server is installed across multiple nodes, you need to set up the H2 database in server mode on a centralized storage.

By following the steps outlined below, you can manually start the H2 database server and configure your application to connect to it using the h2-connector.xml file.

# Step 1: Launch the H2 Database Server

  1. Download the H2 Database distribution from this location (opens new window).
  2. Open a terminal or command prompt.
  3. Navigate to the directory where the h2-yc.jar was downloaded in step #1
  4. Run the following command to start the H2 server:
java -cp h2-yc.jar org.h2.tools.Server -tcp -tcpPort <TCP-PORT> -tcpAllowOthers -baseDir <DIRECTORY>
1

Here replace

<TCP-PORT> - Port number in which H2 DB should listen for server connections.
<DIRECTORY> - Directory in which H2 DB files will be stored.

Example:

java -cp h2-yc.jar org.h2.tools.Server -tcp -tcpPort 9092 -tcpAllowOthers -baseDir /tmp/h2
1

# Step 2: Configure H2 Database

Open Command Prompt or Terminal: Navigate to the directory where the H2 jar file is located.

Run H2 Shell Command: Use the following command to start the H2 Shell.

java -cp h2-yc.jar org.h2.tools.Shell
1

H2 Shell Welcome Message: You will see the following welcome message:

Welcome to H2 Shell
1

Exit with Ctrl+C

Database URL: You will be prompted to enter the URL for the H2 database. You can specify a path to a file-based database. For example:

URL       jdbc:h2:./path/to/database
1

Driver: Enter the driver class name for H2.

Driver    org.h2.Driver
1

User: Enter the username for the database. The default user for H2 is sa.

User sa
1

Password: Enter the password for the database user. You will need to confirm the password by typing it again. The password input will be hidden for security.

Connection Confirmation: Upon successful connection, you will see a message indicating that you are connected.

Example:

> java -cp h2-yc.jar org.h2.tools.Shell

Welcome to H2 Shell
Exit with Ctrl+C
[Enter]   jdbc:h2:mem:2
URL       jdbc:h2:./path/to/database
[Enter]   org.h2.Driver
Driver
[Enter]   sa
User      your_username
Password  (hidden)
Type the same password again to confirm database creation.
Password  (hidden)
Connected

sql> quit
Connection closed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# Step 3: Connect to the H2 Database Server

To connect application (e.g., yCrash) to the H2 database server that you started manually, follow these steps:

  1. Download (opens new window) the h2-connector.xml configuration file.
  2. Set the database credentials in the h2-connector.xml file.
  3. Place the h2-connector.xml file in the uploads directory of yCrash server.

h2-connector.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
    <entry key="H2_URL">JDBC URL</entry>
    <entry key="H2_USER">username</entry>
    <entry key="H2_PASSWORD">password</entry>
</properties>
1
2
3
4
5
6
7

Replace the following placeholders with your actual database credentials:

  • JDBC URL: JDBC URL where the H2 database is listening that you have configured in step 2.
  • username: The username for accessing the H2 database that you have configured in step 2.
  • password: The password for accessing the H2 database that you have configured in step 2.