Connecting to clickhouse cloud instance throws SQLException No Client available
I am trying to connect to a clickhouse cloud instance via the JDBC driver.
I am using
<include name="clickhouse-jdbc-0.7.1-patch1-all.jar"/>
Code example
private static Connection getConnection(String url, Properties properties)
throws SQLException {
final Connection conn;
conn = DriverManager.getConnection(url, properties);
System.out.println("Connected to: " + conn.getMetaData().getURL());
return conn;
}
/**
* Connects to a DB given connection properties passed via a
* configuration file.
*/
public Connection connect(String configurationFile) {
Properties prop = this.loadConfiguration(configurationFile);
String host = prop.getProperty("HOST");
String port = prop.getProperty("PORT");
String user = prop.getProperty("USERNAME");
String password = prop.getProperty("PASSWORD");
Properties properties = new Properties();
properties.setProperty("user", user);
properties.setProperty("password", password);
properties.setProperty("ssl", "true");
Connection conn = null;
String url = "jdbc:clickhouse://" + host + ":" + port;
try {
return getConnection(url, properties);
} catch (SQLException ex) {
logger.warn("Exception: {}", ex.getMessage());
ex.printStackTrace();
}
return conn;
}
Which throws the error:
2024-11-29 11:39:59,804 WARN o.t.m.d.u.PsqlConnector:72 Exception: No client available
java.sql.SQLException: No client available
at com.clickhouse.jdbc.SqlExceptionUtils.handle(SqlExceptionUtils.java:85)
at com.clickhouse.jdbc.SqlExceptionUtils.create(SqlExceptionUtils.java:31)
at com.clickhouse.jdbc.SqlExceptionUtils.handle(SqlExceptionUtils.java:90)
at com.clickhouse.jdbc.internal.ClickHouseConnectionImpl.getServerInfo(ClickHouseConnectionImpl.java:131)
at com.clickhouse.jdbc.internal.ClickHouseConnectionImpl.<init>(ClickHouseConnectionImpl.java:339)
at com.clickhouse.jdbc.internal.ClickHouseConnectionImpl.<init>(ClickHouseConnectionImpl.java:288)
at com.clickhouse.jdbc.ClickHouseDriver.connect(ClickHouseDriver.java:175)
at com.clickhouse.jdbc.ClickHouseDriver.connect(ClickHouseDriver.java:34)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:681)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:190)
at org.torproject.metrics.descriptorparser.utils.PsqlConnector.getConnection(PsqlConnector.java:44)
at org.torproject.metrics.descriptorparser.utils.PsqlConnector.connect(PsqlConnector.java:70)
at org.torproject.metrics.descriptorparser.Main.run(Main.java:49)
at org.torproject.metrics.descriptorparser.Main.exec(Main.java:38)
at org.torproject.metrics.descriptorparser.Main.main(Main.java:34)
Caused by: java.net.ConnectException: No client available
at com.clickhouse.client.ClickHouseClientBuilder$DummyClient.execute(ClickHouseClientBuilder.java:56)
at com.clickhouse.client.ClickHouseClientBuilder$Agent.sendOnce(ClickHouseClientBuilder.java:282)
at com.clickhouse.client.ClickHouseClientBuilder$Agent.send(ClickHouseClientBuilder.java:294)
at com.clickhouse.client.ClickHouseClientBuilder$Agent.execute(ClickHouseClientBuilder.java:349)
at com.clickhouse.client.ClickHouseClient.executeAndWait(ClickHouseClient.java:881)
at com.clickhouse.client.ClickHouseRequest.executeAndWait(ClickHouseRequest.java:2154)
at com.clickhouse.jdbc.internal.ClickHouseConnectionImpl.getServerInfo(ClickHouseConnectionImpl.java:128)
... 11 more
I can connect without any issues to the http endpoint using curl.
@hiromipaw thank you for reporting. I will look into it.
Meanwhile you may add clickhouse-http-client as dependency.
I am getting the same error and adding clickhouse-http-client is not working. Did you ever get this working by chance? I am using 0.7.2
Good day, @warleysa! What dependencies do you use?
This problem seems linked to shading of some dependencies. It moves some classes and causes that they are not usable. Review of shaded dependencies is needed.
@hiromipaw
I've failed to reproduce the issue with 0.7.1-patch1 and the latest version 0.8.6.
I suspect that it cause by other com.clickhouse dependencies. Would you please list everything you have in you dependencies list from com.clickhouse group?
Thanks!
I am not using clickhouse cloud anymore and locally with the latest version it works.