# How to connect to DB2 using JDBC with securityMechanism=13

**URL:** <https://discuss.elastic.co/t/how-to-connect-to-db2-using-jdbc-with-securitymechanism-13/249410>\
**Category:** Logstash\
**Created:** [September 21, 2020, 6:40pm UTC](https://discuss.elastic.co/t/how-to-connect-to-db2-using-jdbc-with-securitymechanism-13/249410 "2020-09-21T18:40:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fsilveir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fsilveir/32/72274_2.png) [@fsilveir](https://discuss.elastic.co/u/fsilveir)\
**Post date:** [September 21, 2020, 6:40pm UTC](https://discuss.elastic.co/t/how-to-connect-to-db2-using-jdbc-with-securitymechanism-13/249410/1 "2020-09-21T18:40:18Z")

</div>

Hi there,

I'm trying to extract some data from a DB2 database with `securityMechanism 13`. I've tried passing this parameter as part of the connection string as shown below:

```auto
input {
  jdbc {
    jdbc_connection_string => "jdbc:db2://${DB2_HOST}:${DB2_PORT}/${DB2_DB}:securityMechanism=13"
    jdbc_user => "${DB2_USER}"
    jdbc_password => "${DB2_PASSWORD}"
    jdbc_driver_library => "/usr/share/logstash/logstash-core/lib/jars/db2jcc4.jar"
    jdbc_driver_class => "com.ibm.db2.jcc.DB2Driver"
    schedule => "${LOGSTASH_SCHEDULE}"

```

Which returned the following error:

```auto
[2020-09-21T12:16:01,092][ERROR][logstash.inputs.jdbc] Unable to connect to database. Tried 1 times {:error_message=>"Java::ComIbmD
b2JccAm::SqlSyntaxErrorException: [jcc][10214][10050][4.21.29] java.util.Properties object passed to java.sql.Driver.connect() cannot be
 overridden by URL: jdbc:db2://MYSERVER:50000/MYDATABASE:securityMechanism=13;. ERRORCODE=-4461, SQLSTATE=42815"}
{ 2054 rufus-scheduler intercepted an error:
  2054 job:
  2054 Rufus::Scheduler::CronJob "* * * * *" {}
  2054 error:
  2054 2054
  2054 Sequel::DatabaseConnectionError
  2054 Java::ComIbmDb2JccAm::SqlSyntaxErrorException: [jcc][10214][10050][4.21.29] java.util.Properties object passed to java.sql.Dr
iver.connect() cannot be overridden by URL: jdbc:db2://MYSERVER:50000/MYDATABASE:securityMechanism=13;. ERRORCODE=-4461, SQLSTATE=42815

```

I've also tried passing `securityMechanism` as part of `sequel_opts`, as indicated by some other folks on other posts, as shown below:

```auto
  jdbc {
    jdbc_connection_string => "jdbc:db2://${DB2_HOST}:${DB2_PORT}/${DB2_DB}"
    jdbc_user => "${DB2_USER}"
    jdbc_password => "${DB2_PASSWORD}"
    jdbc_driver_library => "/usr/share/logstash/logstash-core/lib/jars/db2jcc4.jar"
    jdbc_driver_class => "com.ibm.db2.jcc.DB2Driver"
    sequel_opts => {
              jdbc_properties => {
                "securityMechanism" => "13"
              }
            }

```

However, I had the almost the same error as shown below:

```auto
[2020-09-21T18:35:01,516][ERROR][logstash.inputs.jdbc] Unable to connect to database. Tried 1 times {:error_message=>"Java::ComIbmDb2JccAm::SqlException: [jcc][1071][10615][4.21.29] Caught java.security.InvalidAlgorithmParameterException while initializing Encryption
Manager. See attached Throwable for details. ERRORCODE=-4223, SQLSTATE=null"}
{ 2054 rufus-scheduler intercepted an error:
  2054 job:
  2054 Rufus::Scheduler::CronJob "* * * * *" {}
  2054 error:
  2054 2054
  2054 Sequel::DatabaseConnectionError
  2054 Java::ComIbmDb2JccAm::SqlException: [jcc][1071][10615][4.21.29] Caught java.security.InvalidAlgorithmParameterException while
 initializing EncryptionManager. See attached Throwable for details. ERRORCODE=-4223, SQLSTATE=null

```

For other applications (such as DBVis) the only way I can connect to DB2 with `securityMechanism 13` is using IBM SDK -- however as pointed out in the documentation, IBM's SDK is not currently supported by Logstash.

Any help would be very much appreciated!

Thanks in advance,  
Felipe Silveira

---

<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:** [October 19, 2020, 6:40pm UTC](https://discuss.elastic.co/t/how-to-connect-to-db2-using-jdbc-with-securitymechanism-13/249410/2 "2020-10-19T18:40:22Z")

</div>

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