# Jdbc\_static prepared\_parameters Mismatched number of placeholders error

**URL:** <https://discuss.elastic.co/t/jdbc-static-prepared-parameters-mismatched-number-of-placeholders-error/226833>\
**Category:** Logstash\
**Created:** [April 7, 2020, 6:59am UTC](https://discuss.elastic.co/t/jdbc-static-prepared-parameters-mismatched-number-of-placeholders-error/226833 "2020-04-07T06:59:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgabor](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@jgabor](https://discuss.elastic.co/u/jgabor)\
**Post date:** [April 7, 2020, 6:59am UTC](https://discuss.elastic.co/t/jdbc-static-prepared-parameters-mismatched-number-of-placeholders-error/226833/1 "2020-04-07T06:59:14Z")

</div>

Hi!

When using the jdbc\_static filter and using prepared\_parameters in lookup I get a "Mismatched number of placeholders" error.

The configuration looks like this:

```auto
    local_lookups => [
      {
        id => "local-meld"
        query => "SELECT nr
                        ,meldung 
                    FROM meld 
                   WHERE ts_einfuegung = ?
                     AND system_nr = ?"
        prepared_parameters => ["[ts_einfuegung]", "[system_nr]" ]
        target => "meldungen"
      }
    ]

```

This is the error message:

```auto
[main] Pipeline aborted due to error {:pipeline_id=>"main", :exception=>#<Sequel::Error: Mismatched number of placeholders (2) and placeholder arguments (1) when using placeholder string>

```

The Logstash Version I use is the Docker container logstash:7.6.1

What am I doing wrong here or is this a bug?

Thanks,  
Jan

---

<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:** [April 7, 2020, 3:14pm UTC](https://discuss.elastic.co/t/jdbc-static-prepared-parameters-mismatched-number-of-placeholders-error/226833/2 "2020-04-07T15:14:32Z")

</div>

The jdbc\_static filter [verifies](https://github.com/logstash-plugins/logstash-filter-jdbc_static/blob/2e37229d01e3da0cf7039184cec10bc4ccc54905/lib/logstash/filters/jdbc/lookup.rb#L228) that the number of prepared\_parameters matches the number of question marks in the query.

I would have expected the sequel library to see prepared\_parameters as an array, but the error message has "when using placeholder string", so it went through [this](https://github.com/jeremyevans/sequel/blob/9d780679087f7431139ba7c6558be9da4b12c015/lib/sequel/dataset/sql.rb#L631) code path.

The filter does a [sprintf or get](https://github.com/logstash-plugins/logstash-filter-jdbc_static/blob/2e37229d01e3da0cf7039184cec10bc4ccc54905/lib/logstash/filters/jdbc/lookup.rb#L232) on each prepared parameter. You do not have %{} around your parameters so it will be doing a get.

My guess is that the get fails, because the event is missing either a ts\_einfuegung or system\_nr field. If that is the case I would say it is a bug, but I am unsure whether it is a bug in the filter or a bug in the underlying library.

---

<div class="post-metadata">

**Author:** ![jgabor](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@jgabor](https://discuss.elastic.co/u/jgabor)\
**Post date:** [April 8, 2020, 5:09am UTC](https://discuss.elastic.co/t/jdbc-static-prepared-parameters-mismatched-number-of-placeholders-error/226833/3 "2020-04-08T05:09:54Z")

</div>

I did some additional testing:  
The fields ts\_einfuegung and system\_nr must be present as the sql query in the source looks like this

```auto
SELECT 
 *
  FROM LOG
WHERE TS_EINFUEGUNG IS NOT NULL
  AND SYSTEM_NR IS NOT NULL

```

But: when using parameters instead of prepared\_parameters it works:

```auto
local_lookups => [
      {
        id => "local-meld"
        query => "SELECT nr
                        ,meldung 
                    FROM meld 
                   WHERE ts_einfuegung = :ts_einfuegung
                     AND system_nr = :system_nr"
        parameters =>{ ts_einfuegung => "[ts_einfuegung]" system_nr => "[system_nr]" }
        target => "meldungen"
      }
    ]

```

Well, this is a feasable workaround for my problem but I really would like to know if prepared\_statements make a difference in performance

Jan

---

<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:** [May 6, 2020, 5:09am UTC](https://discuss.elastic.co/t/jdbc-static-prepared-parameters-mismatched-number-of-placeholders-error/226833/4 "2020-05-06T05:09:59Z")

</div>

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