|
| 1 | +--- |
| 2 | +title: "Using the JDBC Driver" |
| 3 | +parent: "ODBC/JDBC Interfaces" |
| 4 | +--- |
| 5 | +This section explains how to install and use the JDBC driver for Apache Drill. For specific examples of client tool connections to Drill via JDBC, see [Using JDBC with SQuirreL]({{ site.baseurl }}/docs/.../) and [Configuring Spotfire Server]({{ site.baseurl }}/docs/.../). |
| 6 | + |
| 7 | + |
| 8 | +### Prerequisites |
| 9 | + |
| 10 | + * JRE 7 or JDK 7 |
| 11 | + * Drill installed either in embedded mode or in distributed mode on one or more nodes in a cluster. Refer to the [Install Drill]({{ site.baseurl }}/docs/install-drill/) documentation for more information. |
| 12 | + * The client must be able to resolve the actual hostname of the Drill node(s) with the IP(s). Verify that a DNS entry was created on the client machine for the Drill node(s). If a DNS entry does not exist, create the entry for the Drill node(s). |
| 13 | + |
| 14 | + * For Windows, create the entry in the %WINDIR%\system32\drivers\etc\hosts file. |
| 15 | + * For Linux and Mac OSX, create the entry in /etc/hosts. |
| 16 | +<drill-machine-IP> <drill-machine-hostname> |
| 17 | + For example: `127.0.1.1 maprdemo` |
| 18 | + |
| 19 | + |
| 20 | +---------- |
| 21 | + |
| 22 | +### Getting the Drill JDBC Driver |
| 23 | + |
| 24 | +The Drill JDBC Driver `JAR` file must exist in a directory on a client machine so you can configure the driver for the application or third-party tool that you intend to use. You can obtain the driver in two different ways: |
| 25 | + |
| 26 | +1. Copy the `drill-jdbc-all` JAR file from the following Drill installation directory on a node where Drill is installed to a directory on your client machine: |
| 27 | + |
| 28 | + <drill_installation_directory>/jars/jdbc-driver/drill-jdbc-all-<version>.jar |
| 29 | + |
| 30 | + For example, on a MapR cluster: `/opt/mapr/drill/drill-1.0.0/jars/jdbc-driver/drill-jdbc-all-1.0.0-mapr-r1.jar` |
| 31 | + |
| 32 | +2. Download the following tar file to a location on your client machine: [apache- |
| 33 | +drill-1.0.0.tar.gz](http://apache.osuosl.org/drill/drill-1.0.0/apache-drill-1.0.0-src.tar.gz) and extract the file. You may need to use a decompression utility, such as [7-zip](http://www.7-zip.org/). The driver is extracted to the following directory: |
| 34 | + |
| 35 | + <drill-home>\apache-drill-\<version>\jars\jdbc-driver\drill-jdbc-all-<version>.jar |
| 36 | + |
| 37 | +---------- |
| 38 | + |
| 39 | +### Configuring a Driver Application or Client |
| 40 | + |
| 41 | +To configure a JDBC application, users have to: |
| 42 | + |
| 43 | +1. Put the Drill JDBC jar file on the class path. |
| 44 | +2. Use a valid Drill JDBC URL. |
| 45 | +3. Configure tools or application code with the name of the Drill driver class. |
| 46 | + |
| 47 | +Most client tools provide a UI where you can enter all of the required connection information, including the Driver location, connection URL, and driver class name. |
| 48 | + |
| 49 | +### JDBC Driver URLs |
| 50 | + |
| 51 | +The driver URLs that you use to create JDBC connection strings must be formed as follows: |
| 52 | + |
| 53 | +`jdbc:drill:zk=<zookeeper_quorum>:<port>/<drill_directory_in_zookeeper>/<cluster_ID>;schema=<schema_to_use_as_default>` |
| 54 | + |
| 55 | +Any Drill JDBC URL must start with: `jdbc:drill`. |
| 56 | + |
| 57 | +**ZooKeeper Quorum** |
| 58 | + |
| 59 | +To connect to a cluster, specify the ZooKeeper quorum as a list of hostnames or IP addresses. |
| 60 | + |
| 61 | +**ZooKeeper Port Number** |
| 62 | + |
| 63 | +The default ZooKeeper port is 2181. On a MapR cluster, the ZooKeeper port is 5181. |
| 64 | + |
| 65 | +**Drill Directory in ZooKeeper** |
| 66 | + |
| 67 | +The name of the Drill directory stored in ZooKeeper is `/drill`. |
| 68 | + |
| 69 | +**Cluster ID** |
| 70 | + |
| 71 | +The Drill default cluster ID is <code>drillbits1</code>. |
| 72 | + |
| 73 | +On a MapR cluster, check the following file for the cluster ID: |
| 74 | + |
| 75 | +`/opt/mapr/drill/drill-1.0.0/conf/drill-override.conf` |
| 76 | + |
| 77 | +For example: |
| 78 | + |
| 79 | +`... |
| 80 | +drill.exec: { |
| 81 | + cluster-id: "docs41cluster-drillbits", |
| 82 | + zk.connect: "centos23.lab:5181,centos28.lab:5181,centos29.lab:5181" |
| 83 | +} |
| 84 | +...` |
| 85 | + |
| 86 | +**Schema** |
| 87 | + |
| 88 | +Optionally, include the default schema for the JDBC connection. For example: |
| 89 | + |
| 90 | +`schema=hive` |
| 91 | + |
| 92 | + |
| 93 | +### URL Examples |
| 94 | + |
| 95 | +**Single-Node Installation** |
| 96 | + |
| 97 | +`jdbc:drill:zk=maprdemo:5181` |
| 98 | + |
| 99 | +`jdbc:drill:zk=centos23.lab:5181/drill/docs41cluster-drillbits` |
| 100 | + |
| 101 | +`jdbc:drill:zk=10.10.100.56:5181/drill/drillbits1;schema=hive` |
| 102 | + |
| 103 | +**Cluster Installation** |
| 104 | + |
| 105 | +`jdbc:drill:zk=10.10.100.30:5181,10.10.100.31:5181,10.10.100.32:5181/drill/drillbits1;schema=hive` |
| 106 | + |
| 107 | +--------- |
| 108 | + |
| 109 | +### Driver Class Name |
| 110 | + |
| 111 | +The class name for the JDBC driver is `org.apache.drill.jdbc.Driver` |
| 112 | + |
| 113 | +----------- |
0 commit comments