Updated on 2024-11-28 GMT+08:00

Setting Up a Connection

Function Description

When creating a connection, use ClickHouseDataSource to configure the URL and properties used by the connection.

The user and password configured in clickhouse-example.properties are used as authentication credentials. ClickHouse performs security authentication on the server with the user and password.

Sample Code

ClickHouseDataSource clickHouseDataSource =new ClickHouseDataSource(JDBC_PREFIX + serverList.get(tries - 1), clickHouseProperties);
connection = clickHouseDataSource.getConnection(user, password);

There will be huge security risks if the passwords used for authentication are directly written into the code. You are advised to store the password in ciphertext in the configuration file or environment variables and decrypt them when using them.