Establishing a ClickHouse Connection
This section describes how to establish a ClickHouse connection.
The following code snippets are provided in the initConnection method of the ClickhouseJDBCHaDemo class. During connection creation, the user and password configured in Table 1 are used as authentication credentials. ClickHouse performs security authentication on the server with the user and password.
For versions earlier than MRS 3.3.0, the sample code is as follows:
clickHouseProperties.setPassword(userPass); clickHouseProperties.setUser(userName); BalancedClickhouseDataSource balancedClickhouseDataSource = new BalancedClickhouseDataSource(JDBC_PREFIX + UriList, clickHouseProperties);
For MRS 3.3.0 and later versions, the sample code is as follows:
clickHouseProperties.setProperty(ClickHouseDefaults.USER.getKey(), userName);
clickHouseProperties.setProperty(ClickHouseDefaults.PASSWORD.getKey(), userPass);
try {
clickHouseProperties.setProperty(ClickHouseClientOption.FAILOVER.getKey(), "21");
clickHouseProperties.setProperty(ClickHouseClientOption.LOAD_BALANCING_POLICY.getKey(), "roundRobin");
balancedClickhouseDataSource = new ClickHouseDataSource(JDBC_PREFIX + UriList, clickHouseProperties);
} catch (Exception e) {
LOG.error("Failed to create balancedClickHouseProperties.");
throw e;
} What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot