---
title: "Get a Per-Database Connection String"
url: "https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/get-connection-strings"
version: "7.2"
language: "java"
---

# Get a Per-Database Connection String

> Client language: Java. Also available for [C#](https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/get-connection-strings.md), [Node.js](https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/get-connection-strings.nodejs.md), [Python](https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/get-connection-strings.python.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - Use `GetConnectionStringsOperation` to retrieve a specific connection string,  
>   or all connection strings defined in the database.
>
> - This operation reads connection strings from a single database's record.  
>   To get connection strings defined at the cluster level, see [Get server-wide connection strings](https://docs.ravendb.net/7.2/integrations/connection-strings/server-wide/get-connection-strings.md).
>
> - Learn more about per-database connection strings in [Per-database connection strings - Overview](https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/overview.md).  
>   To create or update a connection string, see [Add or update a connection string](https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/add-or-update-connection-string.java.md).
>
> - In this article:
>   - [Get connection string by name and type](#get-connection-string-by-name-and-type)
>   - [Get all connection strings](#get-all-connection-strings)
>   - [Syntax](#syntax)

## Get connection string by name and type {#get-connection-string-by-name-and-type}

The following example retrieves a `Raven` connection string in the current database:

```java
try (IDocumentStore store = new DocumentStore()) {
    // Request a specific connection string, pass its name and type:
    // =============================================================
    GetConnectionStringsOperation getRavenConStrOp = new GetConnectionStringsOperation(
        "ravendb-connection-string-name", ConnectionStringType.RAVEN);

    GetConnectionStringsResult connectionStrings = store.maintenance().send(getRavenConStrOp);

    // Access results:
    // ===============
    Map<String, RavenConnectionString> ravenConnectionStrings =
        connectionStrings.getRavenConnectionStrings();

    // If no connection string matches the specified name and type, 
    // the result map is null.
    if (ravenConnectionStrings != null) {
        int numberOfRavenConnectionStrings = ravenConnectionStrings.size();
        RavenConnectionString ravenConStr =
            ravenConnectionStrings.get("ravendb-connection-string-name");
    
        String[] targetUrls = ravenConStr.getTopologyDiscoveryUrls();
        String targetDatabase = ravenConStr.getDatabase();
    }
}
```

## Get all connection strings {#get-all-connection-strings}

The following example retrieves all connection strings defined in the database:

```java
try (IDocumentStore store = new DocumentStore()) {
    // Get all connection strings:
    // ===========================
    GetConnectionStringsOperation getAllConStrOp = new GetConnectionStringsOperation();
    GetConnectionStringsResult allConnectionStrings = store.maintenance().send(getAllConStrOp);

    // Access results by connection string type:
    // =========================================

    // Raven
    Map<String, RavenConnectionString> ravenConnectionStrings =
        allConnectionStrings.getRavenConnectionStrings();

    // SQL
    Map<String, SqlConnectionString> sqlConnectionStrings =
        allConnectionStrings.getSqlConnectionStrings();

    // OLAP
    Map<String, OlapConnectionString> olapConnectionStrings =
        allConnectionStrings.getOlapConnectionStrings();

    // Elasticsearch
    Map<String, ElasticSearchConnectionString> elasticsearchConnectionStrings =
        allConnectionStrings.getElasticSearchConnectionStrings();

    // Queue
    Map<String, QueueConnectionString> queueConnectionStrings =
        allConnectionStrings.getQueueConnectionStrings();

    // AI
    Map<String, AiConnectionString> aiConnectionStrings =
        allConnectionStrings.getAiConnectionStrings();
}
```

## Syntax {#syntax}

```java
public GetConnectionStringsOperation()
public GetConnectionStringsOperation(String connectionStringName, ConnectionStringType type)
```

| Parameter | Type | Description |
| - | - | - |
| **connectionStringName** | `String` | Connection string name |
| **type** | `ConnectionStringType` | Connection string type:<br />`RAVEN`, `SQL`, `OLAP`, `ELASTIC_SEARCH`, `QUEUE`, or `AI` |

```java
public enum ConnectionStringType {
    NONE,
    RAVEN,
    SQL,
    OLAP,
    ELASTIC_SEARCH,
    QUEUE,
    AI
}
```

| Operation result | Description |
| - | - |
| `GetConnectionStringsResult` | Class holding all connection strings defined in the database. |

```java
public class GetConnectionStringsResult {
    private Map<String, RavenConnectionString> ravenConnectionStrings;
    private Map<String, SqlConnectionString> sqlConnectionStrings;
    private Map<String, OlapConnectionString> olapConnectionStrings;
    private Map<String, ElasticSearchConnectionString> elasticSearchConnectionStrings;
    private Map<String, QueueConnectionString> queueConnectionStrings;
    private Map<String, AiConnectionString> aiConnectionStrings;

    // Getters and setters are available for each of the above
}
```

> **Note**
>
> The Java client returns connection strings of the `Raven`, `Sql`, `Olap`, `ElasticSearch`, `Queue`
> (Kafka, RabbitMQ, Azure Queue Storage, and Amazon SQS), and `Ai` types.  
> Connection string types that have no matching class in the Java client, such as `Snowflake`, can be viewed from Studio.

> **Note**
>
> Connection string type-specific fields and complete examples are documented in the task or feature articles listed under
> [Connection string per type](https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/add-or-update-connection-string.java.md#connection-string-per-type).
