Member-only story
Connecting Databricks from Azure App Service using Hive-JDBC Driver

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.
- Create a sample table at Azure Databricks.

2. Generate a user token

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

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/.

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())…