从 Tomcat 查询 Impala 抛出 Invalid URL 异常
Posted
技术标签:
【中文标题】从 Tomcat 查询 Impala 抛出 Invalid URL 异常【英文标题】:Querying Impala from Tomcat throws Invalid URL exception 【发布时间】:2014-04-10 01:34:37 【问题描述】:我正在尝试连接到 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。我已经和它摔跤了半天了。我错过了什么?
【问题讨论】:
【参考方案1】:问题解决了。而不是:
Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
我应该使用:
Class.forName("org.apache.hive.jdbc.HiveDriver");
【讨论】:
【参考方案2】:从这一行看很清楚,
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
驱动程序。
希望这会有所帮助!
【讨论】:
我用一个java程序检查了连接url。有用。但是我的具有完全相同 url 的 jsp 代码不起作用。所以我想,tomcat7识别那个url应该有问题。以上是关于从 Tomcat 查询 Impala 抛出 Invalid URL 异常的主要内容,如果未能解决你的问题,请参考以下文章