mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-10-09 01:50:50 +00:00
2e1f6bc56d
* replace exit with assert in test_single_page * improve save_raw_single_page docs option * More grammar fixes * "Built from" link in new tab * fix mistype * Example of include in docs * add anchor to meeting form * Draft of translation helper * WIP on translation helper * Replace some fa docs content with machine translation * add normalize-en-markdown.sh * normalize some en markdown * normalize some en markdown * admonition support * normalize * normalize * normalize * support wide tables * normalize * normalize * normalize * normalize * normalize * normalize * normalize * normalize * normalize * normalize * normalize * normalize * normalize * lightly edited machine translation of introdpection.md * lightly edited machhine translation of lazy.md * WIP on translation utils * Normalize ru docs * Normalize other languages * some fixes * WIP on normalize/translate tools * add requirements.txt * [experimental] add es docs language as machine translated draft * remove duplicate script * Back to wider tab-stop (narrow renders not so well)
84 lines
2.6 KiB
Markdown
84 lines
2.6 KiB
Markdown
# JDBC {#table-engine-jdbc}
|
||
|
||
Allows ClickHouse to connect to external databases via [JDBC](https://en.wikipedia.org/wiki/Java_Database_Connectivity).
|
||
|
||
To implement the JDBC connection, ClickHouse uses the separate program [clickhouse-jdbc-bridge](https://github.com/alex-krash/clickhouse-jdbc-bridge) that should run as a daemon.
|
||
|
||
This engine supports the [Nullable](../../data_types/nullable.md) data type.
|
||
|
||
## Creating a Table {#creating-a-table}
|
||
|
||
``` sql
|
||
CREATE TABLE [IF NOT EXISTS] [db.]table_name
|
||
(
|
||
columns list...
|
||
)
|
||
ENGINE = JDBC(dbms_uri, external_database, external_table)
|
||
```
|
||
|
||
**Engine Parameters**
|
||
|
||
- `dbms_uri` — URI of an external DBMS.
|
||
|
||
Format: `jdbc:<driver_name>://<host_name>:<port>/?user=<username>&password=<password>`.
|
||
Example for MySQL: `jdbc:mysql://localhost:3306/?user=root&password=root`.
|
||
|
||
- `external_database` — Database in an external DBMS.
|
||
|
||
- `external_table` — Name of the table in `external_database`.
|
||
|
||
## Usage Example {#usage-example}
|
||
|
||
Creating a table in MySQL server by connecting directly with it’s console client:
|
||
|
||
``` text
|
||
mysql> CREATE TABLE `test`.`test` (
|
||
-> `int_id` INT NOT NULL AUTO_INCREMENT,
|
||
-> `int_nullable` INT NULL DEFAULT NULL,
|
||
-> `float` FLOAT NOT NULL,
|
||
-> `float_nullable` FLOAT NULL DEFAULT NULL,
|
||
-> PRIMARY KEY (`int_id`));
|
||
Query OK, 0 rows affected (0,09 sec)
|
||
|
||
mysql> insert into test (`int_id`, `float`) VALUES (1,2);
|
||
Query OK, 1 row affected (0,00 sec)
|
||
|
||
mysql> select * from test;
|
||
+--------+--------------+-------+----------------+
|
||
| int_id | int_nullable | float | float_nullable |
|
||
+--------+--------------+-------+----------------+
|
||
| 1 | NULL | 2 | NULL |
|
||
+--------+--------------+-------+----------------+
|
||
1 row in set (0,00 sec)
|
||
```
|
||
|
||
Creating a table in ClickHouse server and selecting data from it:
|
||
|
||
``` sql
|
||
CREATE TABLE jdbc_table
|
||
(
|
||
`int_id` Int32,
|
||
`int_nullable` Nullable(Int32),
|
||
`float` Float32,
|
||
`float_nullable` Nullable(Float32)
|
||
)
|
||
ENGINE JDBC('jdbc:mysql://localhost:3306/?user=root&password=root', 'test', 'test')
|
||
```
|
||
|
||
``` sql
|
||
SELECT *
|
||
FROM jdbc_table
|
||
```
|
||
|
||
``` text
|
||
┌─int_id─┬─int_nullable─┬─float─┬─float_nullable─┐
|
||
│ 1 │ ᴺᵁᴸᴸ │ 2 │ ᴺᵁᴸᴸ │
|
||
└────────┴──────────────┴───────┴────────────────┘
|
||
```
|
||
|
||
## See Also {#see-also}
|
||
|
||
- [JDBC table function](../../query_language/table_functions/jdbc.md).
|
||
|
||
[Original article](https://clickhouse.tech/docs/en/operations/table_engines/jdbc/) <!--hide-->
|