Establishing a ClickHouse Connection
This section describes the sample code for creating 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 following is an example of a generation fragment:
clickHouseProperties.setPassword(userPass); clickHouseProperties.setUser(userName); BalancedClickhouseDataSource balancedClickhouseDataSource = new BalancedClickhouseDataSource(JDBC_PREFIX + UriList, clickHouseProperties);
For MRS 3.3.0 and later versions, the following is an example of a generation fragment:
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; }
Feedback
Was this page helpful?
Provide feedbackThank 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