private static String toSqlState(ClickHouseException e) {
        final String sqlState;
        switch (e.getErrorCode()) {
            case ClickHouseException.ERROR_ABORTED:
            case ClickHouseException.ERROR_CANCELLED:
                sqlState = SQL_STATE_OPERATION_CANCELLED;
                break;
            case ClickHouseException.ERROR_NETWORK:
            case ClickHouseException.ERROR_POCO:
                sqlState = SQL_STATE_CONNECTION_EXCEPTION;
                break;
            case 0:
                sqlState = e.getCause() instanceof ConnectException ? SQL_STATE_CONNECTION_EXCEPTION
                        : SQL_STATE_CLIENT_ERROR;
                break;
            default:
                sqlState = e.getCause() instanceof ConnectException ? SQL_STATE_CONNECTION_EXCEPTION
                        : SQL_STATE_SQL_ERROR;
                break;
        }
        return sqlState;
    }
Helper class for building {@link SQLException}.
clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/SqlExceptionUtils.java