Updated on 2026-06-29 GMT+08:00

Importing and Configuring the ClickHouse Transactions Sample Project

This section applies only to MRS 3.3.0 and later versions.

Context

Obtain the ClickHouse development sample project and import the project to IntelliJ IDEA to learn the sample project.

Prerequisite

Ensure that the difference between the local PC time and the cluster time is less than 5 minutes. If the time difference cannot be determined, contact the system administrator. You can view the time of the cluster in the lower-right corner on the FusionInsight Manager page.

Scenarios

ClickHouse provides sample projects for multiple scenarios to help you quickly get familiar with ClickHouse.

Procedure

  1. Obtain the sample project folder clickhouse-examples and Maven configurations in the src directory where the sample code is decompressed. For details, see Obtaining the MRS Application Development Sample Project.
  2. In the application development environment, import the sample project to the IntelliJ IDEA development environment.

    1. On the IDEA page, choose File > New > Project from Existing Sources.

    2. In the displayed Select File or Directory to Import dialog box, select the pom.xml file in the clickhouse-examples/ClickHouseJDBC-Transaction-JavaExample folder and click OK.
    3. Confirm subsequent configurations and click Next. If there is no special requirement, use the default values.
    4. Select the recommended JDK version and click Finish.

  3. After the project is imported, modify the clickhouse-example.properties file in the conf directory of the sample project based on the actual environment information.

    loadBalancerIPList=
    sslUsed=false
    loadBalancerHttpPort=21425
    loadBalancerHttpsPort=21426
    CLICKHOUSE_SECURITY_ENABLED=true
    user=
    # Passwords stored in plaintext pose security risks. Store them in ciphertext in configuration files or environment variables.
    password=
    #Whether to use transactions.
    useTransaction=true
    #Whether to automatically submit SQL statements. The options are true (automatic) and false (manual). Automatic submission is recommended. Due to the session forwarding mechanism of Balance, SQL statements cannot be manually submitted by connecting to Balance.
    autoCommit=true
    clusterName=default_cluster
    databaseName=testdb
    tableName=testtb
    batchRows=10000
    batchNum=10

    Table 1 Configuration description

    Parameter

    Default Value

    Definition

    loadBalancerIPList

    -

    Mandatory. Set this parameter to the IP address list of LoadBalance.

    • Log in to FusionInsight Manager and choose Cluster > Services > ClickHouse. Click Instances and check the service IP addresses of all ClickHouseBalancer instances.
    • Use commas (,) to separate IP addresses, for example, 10.10.10.100,10.10.10.101.
    • If the IP address is an IPv6 address, convert it, for example, from 192:168:0:0:0:0:158:2 to 192:168::158:2.

    sslUsed

    false

    Whether to enable SSL encryption. You are advised to set this parameter to false for clusters in common mode.

    loadBalancerHttpPort

    21425

    HTTP port number of LoadBalance. If sslUsed is set to false, this parameter cannot be left blank.

    Log in to FusionInsight Manager and choose Cluster > Services > ClickHouse. Click Instance, click the corresponding ClickHouseBalancer instance, choose Instance Configurations > All Configurations, search for lb_http_port, and obtain the parameter value. The default value is 21425.

    loadBalancerHttpsPort

    21426

    HTTPS port number of LoadBalance. If sslUsed is set to true, this parameter cannot be empty.

    Log in to FusionInsight Manager and choose Cluster > Services > ClickHouse. Click Instance, click the corresponding ClickHouseBalancer instance, choose Instance Configurations > All Configurations, search for lb_https_port, and obtain the parameter value. The default value is 21426.

    CLICKHOUSE_SECURITY_ENABLED

    true

    Whether to enable the security mode. Set this parameter to false for a cluster in normal mode.

    user

    No default value

    Developer user created in Table 1.

    password

    No default value

    Password of the development user

    Passwords stored in plaintext pose security risks. Store them in ciphertext in configuration files or environment variables.

    NOTE:

    If the user is created on FusionInsight Manager, you need to change the initial password upon the first login.

    useTransaction

    true

    Whether to use transactions. Set this parameter to true.

    If this parameter is set to true, SQL statements use transactions.

    autoCommit

    true

    Whether to submit data automatically. The available values are:

    true: The transactions are automatically submitted, which is equivalent to using implicit transactions.

    false: The transactions are manually submitted.

    clusterName

    default_cluster

    ClickHouse logical cluster name. Retain the default value.

    databaseName

    testdb

    Name of the database to be created in the sample code project. You can change the database name based on the site requirements.

    tableName

    testtb

    Name of the table to be created in the sample code project. You can change the table name based on the site requirements.

    batchRows

    10000

    Number of data records written in a batch.

    batchNum

    10

    Total number of batches in which data is written.

    ClickHouse uses the LoadBalance-based deployment architecture to automatically distribute user access traffic to multiple backend nodes, expanding service capabilities to external systems and improving fault tolerance. When a client application requests a cluster, Nginx-based ClickHouseBalancer is used to distribute traffic. In this way, data read/write load and high availability of application access are guaranteed.