# Database connectivity

> Database connectivity - データベースは、貴重なビジネスデータを保持するために広く利用されているツールです。
> さまざまなエンタープライズデータベースとの連携を可能にするため、DataRobotにはデータベース接続設定のためのセルフサービスJDBC製品が用意されています。
> 設定した後は、運用データベースからデータを読み取ってモデル構築と予測に使用することができます。 This allows you to quickly train and retrain models
> on that data, and avoids the unnecessary step of exporting data from your enterprise database to a
> CSV for ingest to DataRobot. With access to more diverse data, you can build more accurate models.

This Markdown file sits beside the HTML page at the same path (with a `.md` suffix). It summarizes the topic and lists links for tools and LLM context.

Companion generated at `2026-07-15T05:55:44.619564+00:00` (UTC).

## Primary page

- [Database connectivity](https://docs.datarobot.com/ja/docs/api/dev-learning/python/data/database_connectivity.html.md): Full documentation for this topic (Markdown sidecar).

## Sections on this page

- [データベース接続の用語](https://docs.datarobot.com/ja/docs/api/dev-learning/python/data/database_connectivity.html.md#database-connection-terminology): In-page section heading.
- [ドライバーの作成](https://docs.datarobot.com/ja/docs/api/dev-learning/python/data/database_connectivity.html.md#create-a-driver): In-page section heading.
- [データストアの作成](https://docs.datarobot.com/ja/docs/api/dev-learning/python/data/database_connectivity.html.md#create-a-data-store): In-page section heading.
- [データストアの表示](https://docs.datarobot.com/ja/docs/api/dev-learning/python/data/database_connectivity.html.md#view-data-stores): In-page section heading.
- [データソースの作成](https://docs.datarobot.com/ja/docs/api/dev-learning/python/data/database_connectivity.html.md#create-a-data-source): In-page section heading.
- [Create projects](https://docs.datarobot.com/ja/docs/api/dev-learning/python/data/database_connectivity.html.md#create-projects): In-page section heading.
- [Create prediction datasets](https://docs.datarobot.com/ja/docs/api/dev-learning/python/data/database_connectivity.html.md#create-prediction-datasets): In-page section heading.

## Documentation content

[データベース](https://docs.datarobot.com/ja/docs/workbench/nxt-workbench/dataprep/add-data/connect.html.md) は、貴重なビジネスデータを保持するために広く利用されているツールです。
さまざまなエンタープライズデータベースとの連携を可能にするため、DataRobotにはデータベース接続設定のためのセルフサービスJDBC製品が用意されています。
設定した後は、運用データベースからデータを読み取ってモデル構築と予測に使用することができます。
This allows you to quickly train and retrain models on that data, and avoids the unnecessary step of exporting data from your enterprise database to a CSV for ingest to DataRobot.
With access to more diverse data, you can build more accurate models.

## データベース接続の用語

Database connection configuration uses the following terminology:

- Data store : A configured connection to a database. It has a name, a specified driver, and a JDBC URL. You can register data stores with DataRobot for ease of re-use. A data store has one connector but can have many data sources.
- Data source : A configured connection to the backing data store (the location of data within a given endpoint). A data source specifies, via a SQL query or a selected table and schema data, which data to extract from the data store to use for modeling or predictions. A data source has one data store and one connector but can have many datasets.
- Data driver : The software that allows the application to interact with a database; each data store is associated with either a driver or a connector (created by the administrator). The driver configuration saves the storage location in the application of the JAR file and any additional dependency files associated with the driver.
- Connector : Similarly to data drivers, a connector allows the application to interact with a database; each data store is associated with either a driver or a connector (created by the administrator). The connector configuration saves the storage location in the application of the JAR file and any additional dependency files associated with the connector.
- Dataset : Data, a file or the content of a data source, at a particular point in time. A data source can produce multiple datasets; a dataset has exactly one data source.

Review the workflow to set up projects or prediction datasets below.

1. 管理者は、特定のデータベースにアクセスするために datarobot.DataDriver を設定します。 特定のドライバーについては、この設定はシステム全体に対して一度だけ行われ、その結果として生成されたドライバーはすべてのユーザーによって使用されます。
2. ユーザーは、そのドライバーを使用する特定のデータベースへのインターフェイスを表す datarobot.DataStore を作成します。
3. ユーザーは、データストアから抽出する特定のデータセットを表す datarobot.DataSource を作成します。
4. Users create projects and prediction datasets from a data source.

ユーザーはデータストアとデータソースを管理できます。一方、管理者はドライバーの既存のインスタンスを一覧表示、取得、更新、および削除することによってドライバーを管理できます。

## ドライバーの作成

ドライバーを作成するには、管理者は以下を指定する必要があります。

- class_name ：タイプがJDBCの場合は、ドライバーのJavaクラス名。それ以外の場合はNone。
- canonical_name ：APIおよびGUIに表示するわかりやすい名前または結果として生成されたドライバー。
- files ：タイプがJDBCの場合は、ドライバーを含むローカルファイルのリスト。それ以外の場合は省略。
- typ ：ドライバーのタイプを示す列挙型。 デフォルトは dr.enums.DataDriverTypes.JDBC ですが、 dr.enums.DataDriverTypes.DR_DATABASE_V1 にすることもできます。
- database_driver ：JDBC以外で使用するネイティブデータベースのタイプ。 たとえば、 dr.enums.DrDatabaseV1Types.BIGQUERY 。

```
>>> import datarobot as dr
>>> driver = dr.DataDriver.create(
...     class_name='org.postgresql.Driver',
...     canonical_name='PostgreSQL',
...     files=['/tmp/postgresql-42.2.2.jar']
... )
>>> driver
DataDriver('PostgreSQL') 
```

JDBC以外のドライバーを作成するには、以下のコードを使用します。

```
driver = dr.DataDriver.create(None, "BigQuery Native", typ=dr.enums.DataDriverTypes.DR_DATABASE_V1, database_driver=dr.enums.DrDatabaseV1Types.BIGQUERY) 
```

To retrieve information about existing drivers, such as the driver ID for data store creation, you can use `dr.DataDriver.list()`.

## データストアの作成

管理者がドライバーを作成すると、すべてのユーザーがそのドライバーを使用して `DataStore` を作成できます。
データストアは、JDBCデータベースまたはJDBC以外のデータベースを表します。
作成時には、以下を指定する必要があります。

- type ：タイプは dr.enums.DataStoreTypes.DR_DATABASE_V1 または dr.enums.DataStoreTypes.JDBC である必要があります。
- canonical_name ：APIおよびGUIに表示するデータストアのわかりやすい名前。
- driver_id ：データベースへの接続に使用するドライバーのID。
- jdbc_url ：タイプがJDBCの場合にデータベースタイプ、サーバーアドレス、ポート、データベース名などのデータベース接続設定を指定する完全なURL。
- フィールド ：タイプが dr.enums.DataStoreTypes.DR_DATABASE_V1 の場合に使用されるフィールド。 辞書エントリーのリスト。各エントリーにはID、名前、値のフィールドが含まれます。

> [!NOTE] 備考
> Pythonクライアントを使用する場合、データストアはドライバーを用いてのみ作成できます。 Drivers and connectors are not interchangeable for this method. コネクターを用いてデータストアを作成するには、代わりに [REST API](https://docs.datarobot.com/ja/docs/api/reference/public-api/data_connectivity.html.md#create-a-data-store) を使用します。

```
>>> import datarobot as dr
>>> data_store = dr.DataStore.create(
...     data_store_type='jdbc',
...     canonical_name='Demo DB',
...     driver_id='5a6af02eb15372000117c040',
...     jdbc_url='jdbc:postgresql://my.db.address.org:5432/perftest'
... )
>>> data_store
DataStore('Demo DB')
>>> data_store.test(username='username', password='password')
{'message': 'Connection successful'} 
```

代わりにフィールドを使用して、JDBC以外のデータストアを作成できます。

```
>>> fields = [
...     {
...         "id": "bq.project_id",
...         "name": "Project Id",
...         "value": "mldata-358421",
...     }
... ]
>>> data_store = dr.DataStore.create(
...     data_store_type=dr.enums.DataStoreTypes.DR_DATABASE_V1,
...     canonical_name='BigQuery Native Connection',
...     driver_id=driver_id,
...     fields=fields
... ) 
```

### データストアの表示

すでに存在するデータストアを表示するには、以下のコードを使用します。
ただし、 `dr.DataStore.list()` を呼び出しても、すべてのデータストアがデフォルトで表示されるわけではないことに注意してください。
デフォルトではJDBC接続のみが表示されるため、 `typ=dr.enums.DataStoreListTypes.ALL` 引数を明示的に渡す必要があります。

すべてのJDBCデータストアを一覧表示（デフォルト）：

```
data_stores = dr.DataStore.list()

print(f"Found {len(data_stores)} DataStore(s):")
for ds in data_stores:
    print(f"  - {ds.canonical_name} (ID: {ds.id}, Type: {ds.data_store_type})") 
```

すべてのデータストアを一覧表示：

```
all_stores = dr.DataStore.list(typ=dr.enums.DataStoreListTypes.ALL) 
```

## データソースの作成

Once you have a data store, you can query datasets via the data source.
データソースを作成するときは、まずデータストアのIDとクエリーから [datarobot.DataSourceParameters](https://docs.datarobot.com/ja/docs/api/reference/sdk/data-connectivity.html.md#datarobot.DataSourceParameters) オブジェクトを作成します。
次に、以下の内容でデータソースを作成します。

- type ：タイプは dr.enums.DataStoreTypes.DR_DATABASE_V1 または dr.enums.DataStoreTypes.JDBC である必要があります。
- canonical_name ：APIおよびGUIに表示するわかりやすい名前。
- params ： DataSourceParameters オブジェクト。

```
>>> import datarobot as dr
>>> params = dr.DataSourceParameters(
...     data_store_id='5a8ac90b07a57a0001be501e',
...     query='SELECT * FROM airlines10mb WHERE "Year" >= 1995;'
... )
>>> data_source = dr.DataSource.create(
...     data_source_type='jdbc',
...     canonical_name='airlines stats after 1995',
...     params=params
... )
>>> data_source
DataSource('airlines stats after 1995') 
```

フィールドを使用して、JDBC以外のデータストアを作成できます。

```
>>> params = dr.DataSourceParameters(
...     data_store_id=data_store_id,
...     catalog=catalog,
...     schema=schema,
...     table=table,
... )
>>> data_source = dr.DataSource.create(
...     data_source_type=dr.enums.DataStoreTypes.DR_DATABASE_V1,
...     canonical_name='BigQuery Data Source',
...     driver_id=driver_id,
...     params=params
... ) 
```

## Create projects

You can create new projects from a data source, demonstrated below.

```
>>> import datarobot as dr
>>> project = dr.Project.create_from_data_source(
...     data_source_id='5ae6eee9962d740dd7b86886',
...     username='username',
...     password='password'
... ) 
```

As of v3.0 of the Python API client, you can alternatively pass in the `credential_id` of an existing [Dataset.Credential](https://docs.datarobot.com/ja/docs/api/dev-learning/python/admin/credentials.html.md#datarobot.models.Credential) object.

```
>>> import datarobot as dr
>>> project = dr.Project.create_from_data_source(
...     data_source_id='5ae6eee9962d740dd7b86886',
...     credential_id='9963d544d5ce3se783r12190'
... ) 
```

あるいは、 `CredentialDataSchema` に準拠した `credential_data` を渡します。

```
>>> import datarobot as dr
>>> s3_credential_data = {"credentialType": "s3", "awsAccessKeyId": "key123", "awsSecretAccessKey": "secret123"}
>>> project = dr.Project.create_from_data_source(
...     data_source_id='5ae6eee9962d740dd7b86886',
...     credential_data=s3_credential_data
... ) 
```

## Create prediction datasets

Given a data source, new prediction datasets can be created for any project.

```
>>> import datarobot as dr
>>> project = dr.Project.get('5ae6f296962d740dd7b86887')
>>> prediction_dataset = project.upload_dataset_from_data_source(
...     data_source_id='5ae6eee9962d740dd7b86886',
...     username='username',
...     password='password'
... ) 
```
