# JDBC通用 解釋器
原文鏈接 : [http://zeppelin.apache.org/docs/0.7.2/interpreter/jdbc.html](http://zeppelin.apache.org/docs/0.7.2/interpreter/jdbc.html)
譯文鏈接 : [http://www.apache.wiki/pages/viewpage.action?pageId=10030838](http://www.apache.wiki/pages/viewpage.action?pageId=10030838)
貢獻者 : [片刻](/display/~jiangzhonglian) [ApacheCN](/display/~apachecn) [Apache中文網](/display/~apachechina)
## 概述
JDBC解釋器允許您無縫地創建到任何數據源的JDBC連接。
在運行每個語句后,將立即應用插入,更新和升級。
到目前為止,已經通過以下測試:
|  |
* [Postgresql](http://www.postgresql.org/)?-?[JDBC驅動](https://jdbc.postgresql.org/)
* [Mysql](https://www.mysql.com/)?-?[JDBC驅動](https://dev.mysql.com/downloads/connector/j/)
* [MariaDB](https://mariadb.org/)?-?[JDBC驅動程序](https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/)
* [Redshift](https://aws.amazon.com/documentation/redshift/)?-?[JDBC驅動](https://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection.html)
* [Apache Hive](https://hive.apache.org/)?-?[JDBC驅動](https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-JDBC)
* [Apache Phoenix](https://phoenix.apache.org/) 本身是一個JDBC驅動
* [Apache Drill](https://drill.apache.org/)?-?[JDBC驅動](https://drill.apache.org/docs/using-the-jdbc-driver)
* [Apache Tajo](http://tajo.apache.org/)?-?[JDBC驅動](https://tajo.apache.org/docs/current/jdbc_driver.html)
|
| --- | --- |
如果您使用的其他數據庫不在上述列表中,請隨時分享您的用例。這將有助于提高JDBC解釋器的功能。
## 創建一個新的JDBC解釋器
首先,`+ Create`在解釋器設置頁面的右上角單擊按鈕。

?`Interpreter name`用任何你想要用作別名的填充字段(如mysql,mysql2,hive,redshift等)。請注意,此別名將用于`%interpreter_name`在段落中調用解釋器。然后選擇`jdbc`為`Interpreter group`。

JDBC解釋器的默認驅動程序設置為`PostgreSQL`。這意味著Zeppelin?`PostgreSQL`本身就包括驅動程序jar。因此,您不需要為連接添加任何依賴項(例如`PostgreSQL`驅動程序jar?的工件名稱或路徑)`PostgreSQL`。JDBC解釋器屬性默認定義如下。
| 名稱 | 默認值 | 描述 |
| --- | --- | --- |
| common.max_count | 1000 | 要顯示的SQL結果的最大數量 |
| default.driver | org.postgresql.Driver | JDBC驅動程序名稱 |
| default.password | ? | JDBC用戶密碼 |
| default.url | jdbc:postgresql://localhost:5432/ | JDBC的URL |
| default.user | gpadmin | JDBC用戶名 |
如果你想連接其他數據庫如`Mysql`,`Redshift`和`Hive`,你需要編輯的屬性值。您還可以使用[Credential](http://zeppelin.apache.org/docs/0.7.1/security/datasource_authorization.html)進行JDBC身份驗證。在解釋器設置頁面中,如果`default.user`和`default.password`屬性被刪除(使用X按鈕)進行數據庫連接,則JDBC解釋器將從[Credential](http://zeppelin.apache.org/docs/0.7.1/security/datasource_authorization.html)獲取帳戶[信息](http://zeppelin.apache.org/docs/0.7.1/security/datasource_authorization.html)。
下面的例子是`Mysql`連接。

最后一步是**依賴關系設置**。由于Zeppelin?`PostgreSQL`默認僅包含驅動程序jar,因此您需要為其他數據庫添加每個驅動程序的maven坐標或JDBC驅動程序的jar文件路徑。

而已。您可以在[本節](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#examples)中找到更多JDBC連接設置示例([Mysql](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#mysql),[MariaDB](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#mariadb),[Redshift](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#redshift),[Apache Hive](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#apache-hive),[Apache Phoenix](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#apache-phoenix)和[Apache Tajo](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#apache-tajo))。
## 更多屬性
您可以在下面指定更多的JDBC解釋器屬性。
| 物業名稱 | 描述 |
| --- | --- |
| common.max_result | 要顯示的SQL結果的最大數量,以防止瀏覽器超載。這是所有連接的常見屬性 |
| zeppelin.jdbc.auth.type | 支持的認證方式類型有`SIMPLE`,和`KERBEROS` |
| zeppelin.jdbc.principal | 從keytab加載的主要名稱 |
| zeppelin.jdbc.keytab.location | keytab文件的路徑 |
| default.jceks.file | jceks存儲路徑(例如:jceks://file/tmp/zeppelin.jceks) |
| default.jceks.credentialKey | jceks憑證鑰匙 |
您還可以使用此[方法](http://docs.oracle.com/javase/7/docs/api/java/sql/DriverManager.html#getConnection%28java.lang.String,%20java.util.Properties%29)添加更多屬性。例如,如果一個連接需要一個schema參數,那么它必須添加如下的屬性:
| 名稱 | 值 |
| --- | --- |
| default.schema | SCHEMA_NAME |
## 將JDBC插件綁定到筆記本
要綁定解釋器設置頁面中創建的口譯員,請單擊右上角的齒輪圖標。

根據用例選擇(藍色)或取消選擇(白色)解釋器按鈕。如果您需要在筆記本中使用多個解釋器,請激活幾個按鈕。不要忘記點擊`Save`按鈕,否則您將面臨`Interpreter *** is not found`錯誤。

## 如何使用
### 使用JDBC解釋器運行段落
要測試您的數據庫和Zeppelin是否成功連接,請在段落的頂部輸入`%jdbc_interpreter_name`(例如`%mysql`)并運行`show databases`。
```
%jdbc_interpreter_name
show databases?
```
如果段落`FINISHED`沒有任何錯誤,則會在上一個之后自動添加一個新的段落`%jdbc_interpreter_name`。所以你不需要在每個段落的標題中鍵入這個前綴。

### 應用Zeppelin動態表單
您可以在查詢內使用[Zeppelin 動態表單](http://www.apache.wiki/pages/viewpage.action?pageId=10030585)。您可以使用參數化功能`text input`和`select form`參數化功能。
```
%jdbc_interpreter_name
SELECT name, country, performer
FROM demo.performers
WHERE name='{{performer=Sheryl Crow|Doof|Fanfarlo|Los Paranoia}}'?
```
## 例子
以下是您可以參考的一些例子。包括以下連接器,您可以連接每個數據庫,只要它可以配置它的JDBC驅動程序。
### Postgres

屬性[](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#properties)
| 名稱 | 值 |
| --- | --- |
| default.driver | org.postgresql.Driver |
| default.url | jdbc:postgresql://localhost:5432/ |
| default.user | mysql_user |
| default.password | mysql_password |
[Postgres JDBC驅動程序文檔](https://jdbc.postgresql.org/documentation/documentation.html)
依賴
| Artifact | Excludes |
| --- | --- |
| org.postgresql:postgresql:9.4.1211 | ? |
[Maven Repository: org.postgresql:postgresql](https://mvnrepository.com/artifact/org.postgresql/postgresql)
### Mysql

屬性[](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#properties-1)
| 名稱 | 值 |
| --- | --- |
| default.driver | com.mysql.jdbc.Driver |
| default.url | jdbc:mysql://localhost:3306/ |
| default.user | mysql_user |
| default.password | mysql_password |
[Mysql JDBC驅動程序文檔](https://dev.mysql.com/downloads/connector/j/)
依賴[](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#dependencies-1)
| Artifact | Excludes |
| --- | --- |
| mysql:mysql-connector-java:5.1.38 | ? |
[Maven Repository: mysql:mysql-connector-java](https://mvnrepository.com/artifact/mysql/mysql-connector-java)
### MariaDB

屬性
| 名稱 | 值 |
| --- | --- |
| default.driver | org.mariadb.jdbc.Driver |
| default.url | jdbc:mariadb://localhost:3306 |
| default.user | mariadb_user |
| default.password | mariadb_password |
[MariaDB JDBC驅動程序文檔](https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/)
依賴[](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#dependencies-2)
| Artifact | Excludes |
| --- | --- |
| org.mariadb.jdbc:mariadb-java-client:1.5.4 | ? |
[Maven Repository: org.mariadb.jdbc:mariadb-java-client](https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client)
### Redshift[](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#redshift)

屬性
| 名稱 | 值 |
| --- | --- |
| default.driver | com.amazon.redshift.jdbc42.Driver |
| default.url | jdbc:redshift://your-redshift-instance-address.redshift.amazonaws.com:5439/your-database |
| default.user | redshift_user |
| default.password | redshift_password |
[AWS Redshift JDBC驅動程序文檔](http://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection.html)
依賴
| Artifact | Excludes |
| --- | --- |
| com.amazonaws:aws-java-sdk-redshift:1.11.51 | ? |
[Maven Repository: com.amazonaws:aws-java-sdk-redshift](https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-redshift)
### Apache Hive

屬性[](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#properties-4)
| 名稱 | 值 |
| --- | --- |
| default.driver | org.apache.hive.jdbc.HiveDriver |
| default.url | jdbc:hive2://localhost:10000 |
| default.user | hive_user |
| default.password | hive_password |
[Apache Hive 1 JDBC驅動程序文檔](https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-JDBC)?[Apache Hive 2 JDBC驅動程序文檔](https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-JDBC)
依賴
| Artifact | Excludes |
| --- | --- |
| org.apache.hive:hive-jdbc:0.14.0 | ? |
| org.apache.hadoop:hadoop-common:2.6.0 | ? |
[Maven Repository : org.apache.hive:hive-jdbc](https://mvnrepository.com/artifact/org.apache.hive/hive-jdbc)
### Apache Phoenix
Phoenix支持`thick`和`thin`連接類型:
* [Thick client](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#thick-client-connection)更快,但必須直接連接到ZooKeeper和HBase RegionServers。
* [Thin client](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#thin-client-connection)具有較少的依賴關系,并通過[Phoenix Query Server](http://phoenix.apache.org/server.html)實例進行連接。
對您的連接類型使用適當的`default.driver`,`default.url`和依賴性工件。
Thick client連接

屬性
| 名稱 | 值 |
| --- | --- |
| default.driver | org.apache.phoenix.jdbc.PhoenixDriver |
| default.url | jdbc:phoenix:localhost:2181:/hbase-unsecure |
| default.user | phoenix_user |
| default.password | phoenix_password |
依賴[](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#dependencies-5)
| Artifact | Excludes |
| --- | --- |
| org.apache.phoenix:phoenix-core:4.4.0-HBase-1.0 | ? |
[Maven Repository: org.apache.phoenix:phoenix-core](https://mvnrepository.com/artifact/org.apache.phoenix/phoenix-core)
Thin client?連接

屬性[](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#properties-6)
| 名稱 | 值 |
| --- | --- |
| default.driver | org.apache.phoenix.queryserver.client.Driver |
| default.url | jdbc:phoenix:thin:url=http://localhost:8765;serialization=PROTOBUF |
| default.user | phoenix_user |
| default.password | phoenix_password |
依賴
在添加以下依賴項之一之前,首先檢查Phoenix版本。
| Artifact | Excludes | Description |
| --- | --- | --- |
| org.apache.phoenix:phoenix-server-client:4.7.0-HBase-1.1 | ? | For Phoenix?`4.7` |
| org.apache.phoenix:phoenix-queryserver-client:4.8.0-HBase-1.2 | ? | For Phoenix?`4.8+` |
[Maven Repository: org.apache.phoenix:phoenix-queryserver-client](https://mvnrepository.com/artifact/org.apache.phoenix/phoenix-queryserver-client)
### Apache Tajo

屬性[](http://zeppelin.apache.org/docs/0.7.1/interpreter/jdbc.html#properties-7)
| 名稱 | 值 |
| --- | --- |
| default.driver | org.apache.tajo.jdbc.TajoDriver |
| default.url | jdbc:tajo://localhost:26002/default |
[Apache Tajo JDBC驅動程序文檔](https://tajo.apache.org/docs/current/jdbc_driver.html)
依賴
| Artifact | Excludes |
| --- | --- |
| org.apache.tajo:tajo-jdbc:0.11.0 | ? |
[Maven Repository: org.apache.tajo:tajo-jdbc](https://mvnrepository.com/artifact/org.apache.tajo/tajo-jdbc)
## 錯誤報告
如果您使用JDBC解釋器發現錯誤,請創建一個[JIRA](https://issues.apache.org/jira/browse/ZEPPELIN)?ticket。
- 快速入門
- 什么是Apache Zeppelin?
- 安裝
- 配置
- 探索Apache Zeppelin UI
- 教程
- 動態表單
- 發表你的段落
- 自定義Zeppelin主頁
- 升級Zeppelin版本
- 從源碼編譯
- 使用Flink和Spark Clusters安裝Zeppelin教程
- 解釋器
- 概述
- 解釋器安裝
- 解釋器依賴管理
- 解釋器的模擬用戶
- 解釋員執行Hook(實驗)
- Alluxio 解釋器
- Beam 解釋器
- BigQuery 解釋器
- Cassandra CQL 解釋器
- Elasticsearch 解釋器
- Flink 解釋器
- Geode/Gemfire OQL 解釋器
- HBase Shell 解釋器
- HDFS文件系統 解釋器
- Hive 解釋器
- Ignite 解釋器
- JDBC通用 解釋器
- Kylin 解釋器
- Lens 解釋器
- Livy 解釋器
- Markdown 解釋器
- Pig 解釋器
- PostgreSQL, HAWQ 解釋器
- Python 2&3解釋器
- R 解釋器
- Scalding 解釋器
- Scio 解釋器
- Shell 解釋器
- Spark 解釋器
- 系統顯示
- 系統基本顯示
- 后端Angular API
- 前端Angular API
- 更多
- 筆記本存儲
- REST API
- 解釋器 API
- 筆記本 API
- 筆記本資源 API
- 配置 API
- 憑據 API
- Helium API
- Security ( 安全 )
- Shiro 授權
- 筆記本 授權
- 數據源 授權
- Helium 授權
- Advanced ( 高級 )
- Zeppelin on Vagrant VM ( Zeppelin 在 Vagrant 虛擬機上 )
- Zeppelin on Spark Cluster Mode( Spark 集群模式下的 Zeppelin )
- Zeppelin on CDH ( Zeppelin 在 CDH 上 )
- Contibute ( 貢獻 )
- Writing a New Interpreter ( 寫一個新的解釋器 )
- Writing a new Visualization (Experimental) ( 編寫新的可視化(實驗) )
- Writing a new Application (Experimental) ( 寫一個新的應用程序( 實驗 ) )
- Contributing to Apache Zeppelin ( Code ) ( 向 Apache Zeppelin 貢獻( 代碼 ) )
- Contributing to Apache Zeppelin ( Website ) ( 向 Apache Zeppelin 貢獻(website) )