# How do I build a database connection string using KOTS Config templates?

**URL:** https://community.replicated.com/t/how-do-i-build-a-database-connection-string-using-kots-config-templates/1122
**Category:** How do I?
**Tags:** kots, templating, vendor
**Created:** [February 8, 2023, 3:09pm UTC](https://community.replicated.com/t/how-do-i-build-a-database-connection-string-using-kots-config-templates/1122 "2023-02-08T15:09:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ravi\_devarakonda](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/ravi_devarakonda/32/592_2.png) [@ravi\_devarakonda](https://community.replicated.com/u/ravi_devarakonda)
#### Post date: [February 8, 2023, 3:09pm UTC](https://community.replicated.com/t/how-do-i-build-a-database-connection-string-using-kots-config-templates/1122/1 "2023-02-08T15:09:24Z")

</div>

I have a use case where based on the type of database selected, the connection string needs to be built differently. For example:

```auto
items:
        - name: db_type
          title: Database type
          type: select_one
          required: yes
          items:
            - name: postgresql
              title: POSTGRESQL
            - name: oracle
              title: ORACLE

```

Then based on the database selected, I need to build a connection string similar to this:

```auto
- name: db_connection_string
          type: text
          readonly: yes
          value: '{{ if repl{{ConfigOption "db_type" "postgresql"}}}} jdbc:postgresql:server:5432{{ else }} jdbc:oracle:thin@server:1521{{ end }}'

```

something similar to this… Is this possible today?

Best regards,  
Ravi

---

<div class="post-metadata">

### Author: ![adamancini](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/adamancini/32/229_2.png) [@adamancini](https://community.replicated.com/u/adamancini)
#### Post date: [February 8, 2023, 6:17pm UTC](https://community.replicated.com/t/how-do-i-build-a-database-connection-string-using-kots-config-templates/1122/3 "2023-02-08T18:17:27Z")

</div>

@ravi_devarakonda here’s a better example than my original post that one of my colleagues worked up, showing 2 different ways of building the connection string. First, we could use 2 different Config elements, and select the right one with with a `when` statement, OR, in the second case, using one template to build up the string:

```auto
- name: db_type
  title: Database type
  type: select_one
  required: yes
  default: postgresql
  items:
    - name: postgresql
      title: POSTGRESQL
    - name: oracle
      title: ORACLE
- name: db_connection_string
  title: Database Connection String Example
  type: text
  value: jdbc:postgresql:server:5432
  when: repl{{ConfigOptionEquals "db_type" "postgresql"}}
- name: db_connection_string
  title: Database Connection String Example
  type: text
  when: repl{{ConfigOptionEquals "db_type" "oracle"}}
- name: db_connection_string2
  title: Database Connection String Example2
  type: text
  value: '{{repl if ConfigOptionEquals "db_type" "postgresql"}}jdbc:postgresql:server:5432{{repl else}}jdbc:oracle:thin@server:1521{{repl end }}'

```

---

<div class="post-metadata">

### Author: ![ravi\_devarakonda](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/ravi_devarakonda/32/592_2.png) [@ravi\_devarakonda](https://community.replicated.com/u/ravi_devarakonda)
#### Post date: [February 8, 2023, 7:20pm UTC](https://community.replicated.com/t/how-do-i-build-a-database-connection-string-using-kots-config-templates/1122/4 "2023-02-08T19:20:08Z")

</div>

Hello @adamancini,

Thank you very much for this! I was looking for the:

> in the second case, using one template to build up the string:

This is very helpful.  
Much appreciated!

Best Regards,  
Ravi
