2020-04-08 14:22:25 +00:00
|
|
|
|
---
|
2022-08-26 19:07:59 +00:00
|
|
|
|
slug: /zh/sql-reference/table-functions/jdbc
|
2022-04-10 23:08:18 +00:00
|
|
|
|
sidebar_position: 43
|
|
|
|
|
sidebar_label: jdbc
|
2020-04-08 14:22:25 +00:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# jdbc {#table-function-jdbc}
|
|
|
|
|
|
2021-06-11 09:37:38 +00:00
|
|
|
|
`jdbc(datasource, schema, table)` -返回通过JDBC驱动程序连接的表。
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2021-06-11 09:37:38 +00:00
|
|
|
|
此表函数需要单独的 [clickhouse-jdbc-bridge](https://github.com/ClickHouse/clickhouse-jdbc-bridge) 程序才能运行。
|
2020-04-08 14:22:25 +00:00
|
|
|
|
它支持可空类型(基于查询的远程表的DDL)。
|
|
|
|
|
|
2021-03-19 02:32:20 +00:00
|
|
|
|
**示例**
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
SELECT * FROM jdbc('jdbc:mysql://localhost:3306/?user=root&password=root', 'schema', 'table')
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` sql
|
2021-06-11 09:37:38 +00:00
|
|
|
|
SELECT * FROM jdbc('mysql://localhost:3306/?user=root&password=root', 'select * from schema.table')
|
2020-04-08 14:22:25 +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')
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` 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
|
2020-04-08 14:22:25 +00:00
|
|
|
|
```
|