# Database Task

The **Database Task** is used to execute **database commands** as part of a business process.\
It enables a process to interact directly with relational databases by performing SQL operations.

The Database Task is represented as a **rectangular BPMN activity node**, as shown below.

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2F7pw9ERyjaSH6gbfPfuHg%2F0?alt=media" alt=""><figcaption></figcaption></figure>

***

### Purpose

Most business processes rely on data stored in databases.\
The **Database Task** allows processes to:

* Retrieve data (**SELECT**)
* Insert new records (**INSERT**)
* Modify existing data (**UPDATE**)
* Remove data (**DELETE**)

Database Task is commonly used to:

* Fetch information required for decision making
* Persist process execution results
* Update system state during workflow execution
* Share data with downstream activities

***

### Database Task Configuration Overview

The Database Task configuration panel consists of **three main tabs**:

1. **General**
2. **Business Object**
3. **Database Parameter**

Each tab controls a specific aspect of database interaction.

***

### General Tab

The **General** tab contains basic metadata for the Database Task, including:

* Task name
* Task ID
* Description

These properties are used for identification and documentation within the process flow.

> **Important**\
> Always click **Save Panel** to persist any configuration changes.

***

### Business Object Tab

The **Business Object** tab is used to configure and map:

* **Input parameters** passed into the SQL command
* **Output parameters** returned from the database query

This mapping allows:

* Using values from previous tasks in SQL statements
* Passing query results to subsequent process activities

Business Object mapping is required whenever the database result is used later in the process.

***

### Database Parameter Tab

This tab defines **how the database is accessed and what SQL is executed**.

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2F6arh8DhzZtL4Q9gH0wq4%2F1?alt=media" alt=""><figcaption></figcaption></figure>

#### Core Properties

| Property        | Mandatory | Description                                       |
| --------------- | --------- | ------------------------------------------------- |
| Connection Type | Yes       | Type of database connection: **JNDI** or **JDBC** |
| Command Type    | Yes       | SQL operation: **SELECT, INSERT, UPDATE, DELETE** |
| Command         | Yes       | SQL statement to be executed                      |

***

### Connection Type: JNDI

**Java Naming and Directory Interface (JNDI)** allows database connections to be referenced by a logical name configured on the application server.

When **Connection Type = JNDI**, users must define the JNDI name.

| Property        | Mandatory | Description                              |
| --------------- | --------- | ---------------------------------------- |
| Use Environment | No        | Load JNDI name from environment variable |
| JNDI Name       | Yes       | JNDI name for database connection        |

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FmITZJd8B1uoHQmENvfca%2F2?alt=media" alt=""><figcaption></figcaption></figure>

**Recommended usage**:\
JNDI is preferred in production environments because connection details are centrally managed.

***

### Connection Type: JDBC

**Java Database Connectivity (JDBC)** provides direct database connection using driver, URL, and credentials.

When **Connection Type = JDBC**, the following properties must be configured:

| Property             | Mandatory | Description                             |
| -------------------- | --------- | --------------------------------------- |
| JDBC Database Driver | Yes       | Fully qualified driver class name       |
| Use Environment      | No        | Load JDBC URL from environment variable |
| JDBC URL             | Yes       | Database connection URL                 |
| JDBC Username        | Yes       | Database username                       |
| JDBC Password        | Yes       | Database password                       |

JDBC is typically used for:

* Direct database access
* Environments without JNDI configuration
* Development or testing scenarios

***

### Mapping Database Parameters

Within the **Database Parameter** tab, click **Open Mapping Parameter** to map:

* **Process Input → SQL parameters**
* **SQL Result → Process Output**

This opens the **Mapping Parameter** screen, where users can:

* Map input variables to query parameters
* Map query results into Business Objects

This mapping enables seamless data flow between database operations and other process activities.

***

### Best Practices

* Use **JNDI** connections for production deployments
* Avoid hard‑coding credentials when possible
* Validate SQL queries carefully to prevent runtime errors
* Map only required columns to reduce memory usage
* Clearly define Business Object mappings for maintainability

***

### Summary

The **Database Task** enables direct database interaction within ONEWEB process workflows.

Key features:

* Supports SELECT, INSERT, UPDATE, DELETE
* Flexible connection options (JNDI, JDBC)
* Full input/output parameter mapping
* Seamless integration with Business Objects
* Essential for data‑driven business processes

Proper configuration of the Database Task ensures **reliable, secure, and maintainable database integration** in Process Designer.


---

# 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://docs.onewebstack.com/oneweb-platform-th/designer-reference/process-designer/process-designer-component/activity-nodes/database-task.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.
