2020-04-03 13:23:32 +00:00
|
|
|
---
|
|
|
|
toc_priority: 43
|
|
|
|
toc_title: jdbc
|
|
|
|
---
|
|
|
|
|
2020-03-21 04:11:51 +00:00
|
|
|
# jdbc {#table-function-jdbc}
|
2018-10-16 10:47:17 +00:00
|
|
|
|
2021-06-11 09:37:38 +00:00
|
|
|
`jdbc(datasource, schema, table)` - returns table that is connected via JDBC driver.
|
2018-10-16 10:47:17 +00:00
|
|
|
|
2021-06-11 09:37:38 +00:00
|
|
|
This table function requires separate [clickhouse-jdbc-bridge](https://github.com/ClickHouse/clickhouse-jdbc-bridge) program to be running.
|
2018-10-16 10:47:17 +00:00
|
|
|
It supports Nullable types (based on DDL of remote table that is queried).
|
|
|
|
|
|
|
|
**Examples**
|
|
|
|
|
2020-03-20 10:10:48 +00:00
|
|
|
``` sql
|
2018-10-16 10:47:17 +00:00
|
|
|
SELECT * FROM jdbc('jdbc:mysql://localhost:3306/?user=root&password=root', 'schema', 'table')
|
|
|
|
```
|
|
|
|
|
2020-03-20 10:10:48 +00:00
|
|
|
``` sql
|
2021-06-11 09:37:38 +00:00
|
|
|
SELECT * FROM jdbc('mysql://localhost:3306/?user=root&password=root', 'select * from schema.table')
|
2018-10-16 10:47:17 +00:00
|
|
|
```
|
|
|
|
|
2020-03-20 10:10:48 +00:00
|
|
|
``` sql
|
2021-06-11 09:37:38 +00:00
|
|
|
SELECT * FROM jdbc('mysql-dev?p1=233', 'num Int32', 'select toInt32OrZero(''{{p1}}'') as num')
|
2018-10-16 10:47:17 +00:00
|
|
|
```
|
|
|
|
|
2021-06-11 09:37:38 +00:00
|
|
|
``` sql
|
2021-07-29 15:20:55 +00:00
|
|
|
SELECT *
|
2021-06-11 09:37:38 +00:00
|
|
|
FROM jdbc('mysql-dev?p1=233', 'num Int32', 'select toInt32OrZero(''{{p1}}'') as num')
|
|
|
|
```
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
SELECT a.datasource AS server1, b.datasource AS server2, b.name AS db
|
|
|
|
FROM jdbc('mysql-dev?datasource_column', 'show databases') a
|
|
|
|
INNER JOIN jdbc('self?datasource_column', 'show databases') b ON a.Database = b.name
|
|
|
|
```
|
|
|
|
|
2021-09-19 20:05:54 +00:00
|
|
|
[Original article](https://clickhouse.com/docs/en/query_language/table_functions/jdbc/) <!--hide-->
|