从tomcat查询impala引发无效的url异常

moiiocjp  于 2021-06-26  发布在  Impala
关注(0)|答案(2)|浏览(634)

我正在尝试连接到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。我已经和它搏斗了半天了。我错过了什么?

sauutmhj

sauutmhj1#

从这条线看很清楚,

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

这条线 "jdbc:hive2://localhost:21050/;auth=noSasl" 无效。那就去查一下那个警察 url 连接您的 jdbc 司机。
希望这有帮助!!

gupuwyp2

gupuwyp22#

问题解决了。而不是:

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

我应该用:

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

相关问题