从Tomcat查询Impala会引发无效的URL异常

时间:2014-04-10 01:34:37

标签: java jsp tomcat impala cloudera-cdh

我正在尝试连接到Impala并从我的Web应用程序运行查询。这是我的jsp代码:

<%@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>

以下是我在浏览器中收到的错误:

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)

我正在使用CDH4和Tomcat7。我已经和它摔跤了半天了。我错过了什么?

2 个答案:

答案 0 :(得分:2)

问题解决了。而不是:

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

我应该使用:

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

答案 1 :(得分:1)

从这条线上可以清楚地看出,

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

此行"jdbc:hive2://localhost:21050/;auth=noSasl"无效。因此请检查coorect url以连接您的jdbc驱动程序。

希望这会有所帮助!!