# Dynamically set connection string on jdbc\_streaming filter

**URL:** <https://discuss.elastic.co/t/dynamically-set-connection-string-on-jdbc-streaming-filter/361675>\
**Category:** Logstash\
**Tags:** jdbc\
**Created:** [June 18, 2024, 7:52pm UTC](https://discuss.elastic.co/t/dynamically-set-connection-string-on-jdbc-streaming-filter/361675 "2024-06-18T19:52:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DMcP89](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dmcp89/32/135378_2.png) [@DMcP89](https://discuss.elastic.co/u/DMcP89)\
**Post date:** [June 18, 2024, 7:52pm UTC](https://discuss.elastic.co/t/dynamically-set-connection-string-on-jdbc-streaming-filter/361675/1 "2024-06-18T19:52:39Z")

</div>

Is it possible to dynamically set the connection string on a jdbc\_streaming filter?

Something like this for example:

```auto
    mutate {
        add_field => {
            "connection_string" => "jdbc:sqlserver://test.mydb.com:1433;databaseName=%{[database_name]};integratedSecurity=false;trustServerCertificate=true"
        }
    }

 jdbc_streaming {
        jdbc_connection_string => "%{[connection_string]}"
        jdbc_user => "test-user"
        jdbc_password => "test-pass"
        jdbc_driver_library => "C:\Program Files\Logstash\resources\drivers\mssql-jdbc-10.2.1.jre17.jar"
        jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
        statement => "SELECT * FROM my-table"
}

```

Based on my testing it does not seem possible in 7.17 as when I tried this the pipeline failed to be created:

```auto
 Pipeline error {:pipeline_id=>"test-pipeline", :exception=>#<URI::InvalidURIError: bad URI(is not URI?): %{[connection_string]}>,

```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [June 18, 2024, 11:56pm UTC](https://discuss.elastic.co/t/dynamically-set-connection-string-on-jdbc-streaming-filter/361675/2 "2024-06-18T23:56:07Z")

</div>

> [@DMcP89](#):
>
> Is it possible to dynamically set the connection string on a jdbc\_streaming filter?

No, it is not. The filter does not sprintf the connection string, it [just passes it](https://github.com/logstash-plugins/logstash-integration-jdbc/blob/c0061a6f14f0b1ebf96b4141b44fb822a3e8f881/lib/logstash/plugin_mixins/jdbc_streaming.rb#L62) to the SQL library that the filter is built on top of.

That connection is [set up once](https://github.com/logstash-plugins/logstash-integration-jdbc/blob/c0061a6f14f0b1ebf96b4141b44fb822a3e8f881/lib/logstash/filters/jdbc_streaming.rb#L122) when the pipeline is first configured. If it were dynamic the filter might have to rebuild the connection for every event, which would add a lot of overhead.
