【问题标题】:Clickhouse jdbc driver connection issueClickhouse jdbc驱动连接问题
【发布时间】:2021-12-29 09:30:33
【问题描述】:

我们正在尝试使用 jdbc 驱动程序连接到 clickhouse 服务器。我们的代码 sn-p 在 scala 中,在 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()
    }

我们得到以下错误:

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

我们浏览了其他几个页面,提到了同样的错误,并且按照那里的建议,我们使用了最新版本的驱动程序(0.3.1-patch)。

我们也尝试使用另一个驱动程序 (clickhouse-native-jdbc) 并得到相同的错误。

为了添加更多上下文,我们尝试使用 python clickhouse-driver 和以下代码 sn-p -

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)

这行得通。

我们不确定这是否仅仅是因为 ssl 安全设置为 true 而验证设置为 false。如果是这样,应该如何将这些添加到上面使用的驱动程序中?如果这不是原因,那可能是什么原因?

【问题讨论】:

  • 为什么是 9001?是 Clickhouse TCP 端口的映射吗? Clickhouse官方驱动使用HTTP协议,所以你应该使用HTTP端口(默认8123)
  • @AndreiKoch,谢谢!不知道这个。将其更改为 8123 有效。

标签: java jdbc clickhouse clickhouse-client


【解决方案1】:

正如@AndreiKoch 在问题的 cmets 中提到的,我们假设 jdbc 驱动程序将使用 9001,就像在 python 中使用的 clickhouse-driver 一样: https://clickhouse-driver.readthedocs.io/_/downloads/en/0.0.20/pdf/.

但是,原生 jdbc 驱动程序(在 scala sn-p 中使用)通过端口 8123 使用 HTTP。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-25
    • 2012-02-28
    • 2017-12-07
    • 2021-04-05
    • 2011-03-05
    • 2020-01-06
    • 2012-03-10
    • 1970-01-01
    相关资源
    最近更新 更多