Question

I am trying to connect to Impala and run a query from my web application. Here is my jsp code:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ 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" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>



<%

    Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");

    Connection con = DriverManager.getConnection("jdbc:hive2://localhost:21050/;auth=noSasl");
    Statement stmt = con.createStatement();

     String sql = "select * from logdata limit 10";       
     System.out.println("Running: " + sql);
     ResultSet res = stmt.executeQuery(sql);

    while (res.next()) {
      System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
    }

%>
    </body>
</html>

Here is the error that I get in my browser:

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: java.sql.SQLException: Invalid URL: jdbc:hive2://localhost:21050/;auth=noSasl
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

javax.servlet.ServletException: java.sql.SQLException: Invalid URL: jdbc:hive2://localhost:21050/;auth=noSasl
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
    org.apache.jsp.web.index_jsp._jspService(index_jsp.java:114)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

java.sql.SQLException: Invalid URL: jdbc:hive2://localhost:21050/;auth=noSasl
    org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:86)
    org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:106)
    java.sql.DriverManager.getConnection(DriverManager.java:615)
    java.sql.DriverManager.getConnection(DriverManager.java:213)
    org.apache.jsp.web.index_jsp._jspService(index_jsp.java:91)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

I am using CDH4 and Tomcat7. I've been wrestling with it for half a day now. What am I missing?

Was it helpful?

Solution

The problem is solved. Instead of:

Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");

I should have used:

Class.forName("org.apache.hive.jdbc.HiveDriver");

OTHER TIPS

Its very clear from this line ,

org.apache.jasper.JasperException: javax.servlet.ServletException: 
java.sql.SQLException:
Invalid URL: jdbc:hive2://localhost:21050/;auth=noSasl

this line "jdbc:hive2://localhost:21050/;auth=noSasl" is invalid . so check for the coorect url to connect your jdbc driver .

Hope this helps!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top