# Dynamic query in jdbc plugin

**URL:** <https://discuss.elastic.co/t/dynamic-query-in-jdbc-plugin/264806>\
**Category:** Logstash\
**Created:** [February 19, 2021, 7:34am UTC](https://discuss.elastic.co/t/dynamic-query-in-jdbc-plugin/264806 "2021-02-19T07:34:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![niki1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niki1/32/84163_2.png) [@niki1](https://discuss.elastic.co/u/niki1)\
**Post date:** [February 19, 2021, 7:34am UTC](https://discuss.elastic.co/t/dynamic-query-in-jdbc-plugin/264806/1 "2021-02-19T07:34:20Z")

</div>

I got a mysql(or any other relational database) with a table like this:

> ```
> id,name,prod
> 11,alex,car
> 22,alice,ship
> 33,bob,airplane
> 
> ```

and I have messages going through logstash pipeline like this:

> ```
> 11,20210215,ford,....
> 22.20210216,renault,...
> 33,20210217,toyota,...
> 
> ```

and I want to use jdbc plugin to perform a query like this:  
`SELECT name where id=$id;`  
and grab the name where id is dynamicaly be read from the message and replace it .  
after that the messages should be like this:

> ```
> alex,20210215,ford,....
> alice.20210216,renault,...
> bob,20210217,toyota,...
> 
> ```

I appreciate if anyone can help me with this.

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [February 20, 2021, 7:07am UTC](https://discuss.elastic.co/t/dynamic-query-in-jdbc-plugin/264806/2 "2021-02-20T07:07:40Z")

</div>

Hello Niki,

Have you already checked the example in the documentation - I think this explains your usecase really well: [Jdbc\_streaming filter plugin | Logstash Reference [7.11] | Elastic](https://www.elastic.co/guide/en/logstash/current/plugins-filters-jdbc_streaming.html)

Or do you have a specific problem with the filter you need help with?

Best regards  
Wolfram

---

<div class="post-metadata">

**Author:** ![niki1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niki1/32/84163_2.png) [@niki1](https://discuss.elastic.co/u/niki1)\
**Post date:** [February 22, 2021, 6:56pm UTC](https://discuss.elastic.co/t/dynamic-query-in-jdbc-plugin/264806/3 "2021-02-22T18:56:02Z")

</div>

Hello  
I read the documentation and I thought it is supposed to be a constant query on each filter but based on my above example my jdbc filter should be something like this:

> filter {  
> jdbc\_streaming {  
> jdbc\_driver\_library =\> "/path/to/mysql-connector-java-5.1.34-bin.jar"  
> jdbc\_driver\_class =\> "com.mysql.jdbc.Driver"  
> jdbc\_connection\_string =\> "jdbc:mysql://localhost:3306/mydatabase"  
> jdbc\_user =\> "me"  
> jdbc\_password =\> "secret"  
> statement =\> "select name from mytable WHERE id= :id"  
> parameters =\> { "id" =\> "id"}  
> target =\> "name"  
> }  
> }  
> am i correct?  
> thank you for the answer.

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [February 22, 2021, 6:57pm UTC](https://discuss.elastic.co/t/dynamic-query-in-jdbc-plugin/264806/4 "2021-02-22T18:57:29Z")

</div>

Yes, this is correct

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 22, 2021, 6:58pm UTC](https://discuss.elastic.co/t/dynamic-query-in-jdbc-plugin/264806/5 "2021-03-22T18:58:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
