Member-only story

Connecting Databricks from Azure App Service using Hive-JDBC Driver

Prosenjit Chakraborty
3 min readJan 29, 2019

--

You may have a use case where you need to query and report data from Hive. Azure Databricks supports various Business Intelligence tools (ref: https://docs.azuredatabricks.net/user-guide/bi/index.html) to serve the purpose.

In this example, we’ll be creating an Azure App Service which will fetch records using Hive-JDBC driver.

  1. Create a sample table at Azure Databricks.
Create a new/use an existing table

2. Generate a user token

Go to Account icon > User Settings > Access Tokens > Generate New Token

3. Note down the JDBC URL. The JDBC/ODBC option is available only with the Premium plan.

Azure Databricks — Cluster Settings screen > Advanced Options> JDBC/ODBC tab

4. Download a JDBC Driver with all the dependencies from: https://docs.azuredatabricks.net/user-guide/bi/workbenchj.html. In my case, it’s uber-hive-jdbc-1.2.1.jar

5. Create a Web Project (follow the link for steps: https://docs.microsoft.com/en-us/azure/app-service/app-service-web-get-started-java) and include the jar under /WEB-INF/lib/.

Eclipse — Project Explorer

6. Write the following code in index.jsp (this is just for an example, ideally we shouldn’t write the logic inside the JSP).

<%@ page import="java.sql.SQLException"%>
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.sql.Statement"%>
<%@ page import="java.sql.DriverManager"%>

<body>
<%
String driver = "org.apache.hive.jdbc.HiveDriver";
%>
<h1>Connect Azure Databricks from Azure Web Apps...</h1>
<%
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
out.println(e.getMessage())…

--

--

Prosenjit Chakraborty
Prosenjit Chakraborty

Written by Prosenjit Chakraborty

Tech enthusiast, Principal Architect — Data & AI.

Responses (1)

Write a response