javajdbcclickhouseclickhouse-client

Clickhouse jdbc driver connection issue


We are trying to connect to a clickhouse server using jdbc drivers. Our code snippet is in scala and would not be much different in java

import java.util.Properties
Class.forName("ru.yandex.clickhouse.ClickHouseDriver")
    var conn : Connection = null
    try {
      conn = DriverManager.getConnection("jdbc:clickhouse://xxxxxx:9001/db_name", "usrname", "pass")
      val stmt = conn.createStatement()
      val sql =s"""select 1""".stripMargin
      stmt.executeQuery(sql)
    } finally {
      if(conn != null)
        conn.close()
    }

We get the following error :

ClickHouseUnknownException: ClickHouse exception, code: 1002, host: xxxxxxx, port: 9001; xxxxxxxxx:9001 failed to respond
Caused by: NoHttpResponseException: xxxxxxxxx:9001 failed to respond

We went through a few other pages mentioning the same error and in keeping with the advice there, we used the latest version of the driver (0.3.1-patch).

We tried this with another driver too (clickhouse-native-jdbc) and got the same error.

To add some more context, we tried using the python clickhouse-driver with the following code snippet -

from clickhouse_driver import Client

conn = Client('xxxxxxxxxx', password='pass', port=9001, user='usrname', verify= False, secure=True)
q1 ="select * from db_name.table limit 5"
result = conn.execute(q1)
print(result)

This works.

We are not sure if this is only because of the ssl secure set to true and the verify set to false. If it is so, how should those be added to the drivers used above? If that is not the cause, what could the cause be?


Solution

  • As mentioned by @AndreiKoch in the comments on the question, we had assumed the jdbc driver would use 9001 just like the clickhouse-driver used in the python: https://clickhouse-driver.readthedocs.io/_/downloads/en/0.0.20/pdf/ .

    However, the native jdbc driver (used in the scala snippet) uses HTTP over port 8123.