JDBC driver

These errors can disrupt the data insertion process and affect system stability. To address this issue you need to adjust a few timeout settings in the client's OS.

### Mac OS[​](#v07-mac-os "Direct link to Mac OS")

On Mac OS, the following settings can be adjusted to resolve the issue:

- `net.inet.tcp.keepidle`: 60000
- `net.inet.tcp.keepintvl`: 45000
- `net.inet.tcp.keepinit`: 45000
- `net.inet.tcp.keepcnt`: 8
- `net.inet.tcp.always_keepalive`: 1

### Linux[​](#v07-linux "Direct link to Linux")

On Linux, the equivalent settings alone may not resolve the issue. Additional steps are required due to the differences in how Linux handles socket keep-alive settings. Follow these steps:

1. Adjust the following Linux kernel parameters in `/etc/sysctl.conf` or a related configuration file:

- `net.inet.tcp.keepidle`: 60000
- `net.inet.tcp.keepintvl`: 45000
- `net.inet.tcp.keepinit`: 45000
- `net.inet.tcp.keepcnt`: 8
- `net.inet.tcp.always_keepalive`: 1
- `net.ipv4.tcp_keepalive_intvl`: 75
- `net.ipv4.tcp_keepalive_probes`: 9
- `net.ipv4.tcp_keepalive_time`: 60 (You may consider lowering this value from the default 300 seconds)

2. After modifying the kernel parameters, apply the changes by running the following command:

```
sudo sysctl -p
```

After Setting those settings, you need to ensure that your client enables the Keep Alive option on the socket:

```
properties.setProperty("socket_keepalive", "true");
```

Note

Currently, you must use Apache HTTP Client library when setting the socket keep-alive, as the other two HTTP client libraries supported by `clickhouse-java` don't allow setting socket options. For a detailed guide, see [Configuring HTTP library](#v07-configuring-http-library).

Alternatively, you can add equivalent parameters to the JDBC URL.

The default socket and connection timeout for the JDBC driver is 30 seconds. The timeout can be increased to support large data insert operations. Use the `options` method on `ClickHouseClient` together with the `SOCKET_TIMEOUT` and `CONNECTION_TIMEOUT` options as defined by `ClickHouseClientOption`:

```
final int MS_12H = 12 * 60 * 60 * 1000; // 12 h in ms
final String sql = "insert into table_a (c1, c2, c3) select c1, c2, c3 from table_b;";

try (ClickHouseClient client = ClickHouseClient.newInstance(ClickHouseProtocol.HTTP)) {
    client.read(servers).write()
        .option(ClickHouseClientOption.SOCKET_TIMEOUT, MS_12H)
        .option(ClickHouseClientOption.CONNECTION_TIMEOUT, MS_12H)
        .query(sql)
        .executeAndWait();
}
```

- [Environment requirements](#environment-requirements)
  - [Setup](#setup)- [Configuration](#configuration)
    - [Connection Properties](#connection-properties)- [Client Identification](#client-identification)- [Operation Identification](#operation-identification)- [Supported data types](#supported-data-types)
      - [JDBC Type Mapping](#jdbc-type-mapping)- [Handling Dates, Times, and Timezones](#handling-dates-times-and-timezones)- [Creating Connection](#creating-connection)- [Supplying Credentials and Settings](#supplying-credentials-and-settings)- [Simple Statement](#simple-statement)- [Insert](#insert)- [`HikariCP`](#hikaricp)- [More Information](#more-information)- [Troubleshooting](#troubleshooting)
                    - [Logging](#logging)- [Resolving JDBC Timeout on Large Inserts](#resolving-jdbc-timeout-on-large-inserts)- [Migration Guide](#migration-guide)
                      - [Key Changes](#key-changes)- [Configuration Changes](#configuration-changes)- [Data Types Changes](#data-types-changes)- [Database Metadata Changes](#database-metadata-changes)- [Environment requirements](#v07-environment-requirements)
                        - [Setup](#v07-setup)- [Configuration](#v07-configuration)- [Supported data types](#v07-supported-data-types)- [Creating Connection](#v07-creating-connection)- [Simple Statement](#v07-simple-statement)- [Insert](#v07-insert)
                                  - [With input table function](#with-input-table-function)- [Insert with placeholders](#insert-with-placeholders)- [Handling DateTime and time zones](#handling-datetime-and-time-zones)- [Handling `AggregateFunction`](#handling-aggregatefunction)- [Configuring HTTP library](#v07-configuring-http-library)- [Connect to ClickHouse with SSL](#connect-to-clickhouse-with-ssl)- [SSL Properties](#ssl-properties)- [Resolving JDBC Timeout on Large Inserts](#v07-resolving-jdbc-timeout-on-large-inserts)
                                              - [Mac OS](#v07-mac-os)- [Linux](#v07-linux)

Was this page helpful?