# H2 database

## Telosys database configuration

Below are examples of typical configurations for **H2** database.

### Since Telosys 4.3

```yaml
  - id: h2-srv
    name: my H2 database server with storage in file
    type: H2 
    # JDBC connection 
    url: jdbc:h2:tcp://localhost:9092/D:/Z/db-data/mydatabase
    user: sa
    password: sa
    # Metadata parameters (schema name in UPPER CASE)
    schema: 'CARS'
```

### Before Telosys 4.3

```yaml
  - id: h2-srv
    name: my H2 database server with storage in file
    type: H2 
    # JDBC connection 
    url: jdbc:h2:tcp://localhost:9092/D:/Z/db-data/mydatabase
    driver: org.h2.Driver
    user: sa
    password: sa
    # Metadata parameters (schema name in UPPER CASE)
    catalog: '!'
    schema: 'CARS'
    tableNamePattern: '%'
    tableTypes: TABLE

```

### JDBC driver

* The H2 JDBC driver is located in the single JAR provided by H2.&#x20;
* JAR file example:  `h2-2.3.232.jar`
* Driver class name : **org.h2.Driver** &#x20;

## Technical information about H2

### Structure

**Database** → **Schema** → Tables/Objects

<div align="left"><figure><img src="/files/u7TzlgVdsXCPF1MDttt4" alt="" width="246"><figcaption></figcaption></figure></div>

* **Database**: In H2, the "database" is basically the connection (in-memory or file). \
  There’s only one database per connection.
* **Schema**: H2 supports schemas, similar to PostgreSQL and SQL Server. \
  Default schema is `PUBLIC`. \
  You can create others (`CREATE SCHEMA sales;`). Objects belong to schemas.

### H2 case conversion rules

* **Unquoted identifiers**
  * Always **converted to UPPERCASE**, following the SQL standard.
  * Applies to both **table names** and **column names**.
* **Quoted identifiers**
  * Case is **preserved exactly as written**
  * They are **case-sensitive** in SQL requests

### H2 modes

H2 can run in **3 main modes**:

1. **Embedded**  (in-process)
   * URL with data storage **in memory**:\
     `jdbc:h2:`**`mem`**`:{database-name}`
   * URL with data storage **in file**: \
     `jdbc:h2:`**`{dir-path}`**`/{database-name}`
2. **Remote Server mode** (accepting external connections)

   * URL with data storage **in memory**:\
     `jdbc:h2:`<mark style="color:red;">**`tcp`**</mark><mark style="color:red;">`://{host}:{port}`</mark>`/`**`mem`**`:{database-name}`
   * URL with data storage **in file**: \
     `jdbc:h2:`<mark style="color:red;">**`tcp`**</mark><mark style="color:red;">`://{host}:{port}`</mark>`/`**`{dir-path}`**`/{database-name}`

   For "SSL" replace "tcp" by "ssl"
3. **Mixed mode** (embedded + server at the same time)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.telosys.org/project-databases/h2-database.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
