# JDBC - SQL Query Issue

**URL:** <https://discuss.elastic.co/t/jdbc-sql-query-issue/290345>\
**Category:** Logstash\
**Created:** [November 27, 2021, 8:59pm UTC](https://discuss.elastic.co/t/jdbc-sql-query-issue/290345 "2021-11-27T20:59:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rojin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rojin/32/97697_2.png) [@rojin](https://discuss.elastic.co/u/rojin)\
**Post date:** [November 27, 2021, 8:59pm UTC](https://discuss.elastic.co/t/jdbc-sql-query-issue/290345/1 "2021-11-27T20:59:52Z")

</div>

Hi! I have a database in MySQL and I want to fetch some info based on IP addresses I get from my client logs. There are ip\_from(VARCHAR 50), ip\_to(VARCHAR 50), ip\_from\_int(INT 10), and ip\_to\_int(INT 10) plus a name(VARCHAR 255) column in my desired table. I have written the filter as below and I want to fetch the name if the IP address is between ip\_from and ip\_to. But it keeps telling me that it cannot recognize INET\_ATON as a function in JDBC. Is there a way I can get my result? the "clientip" is in message field.

```auto
filter {
  jdbc_static {
    loaders => [
      {
        id => "iptable"
        query => "select ip_from, ip_to, name from <db_table_name>"
        local_table => "iptable"
       }
    ]
    local_db_objects => [
      {
        name => "iptable"
        index_columns => ["name"]
        columns => [
          ["ip_from", "varchar(50)"],
          ["ip_to", "varchar(50)"],
          ["name", "VARCHAR(255)"]
        ]
      }
    ]
    local_lookups => [
      {
        id => "get-data-name"
        query => "SELECT name FROM iptable WHERE inet_aton(ip_from) <= inet_aton(:cip) and inet_aton(ip_to) >= inet_aton(:cip)"
        parameters => { "cip" => "[clientip]"}
        target => "result"
      }
    ]
    add_field => { data_name => "%{[result][0][name]}" }
    remove_field => ["result"]

    loader_schedule => "0 */2 * * *"
    jdbc_user => "<user>"
    jdbc_password => "<password>"
    jdbc_driver_class => "com.mysql.cj.jdbc.Driver"
    jdbc_connection_string => "jdbc:mysql://<mysql-ip>:<port>/<db>"
    staging_directory => "/var/logstash/jdbc_static/import_data/"
  }
 }

```

Here's the exception:

```auto
:exception=>"Java::JavaSql::SQLSyntaxErrorException: 'INET_ATON' is not recognized as a function or procedure.

```

I'd really appreciate if someone could help!  
@Badger @magnusbaeck

---

<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:** [December 25, 2021, 9:00pm UTC](https://discuss.elastic.co/t/jdbc-sql-query-issue/290345/2 "2021-12-25T21:00:27Z")

</div>

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