简体   繁体   English

java.sql.SQLException: 使用 jsp 连接时找不到适合 jdbc:hive2://localhost:10000/default 的驱动程序

[英]java.sql.SQLException: No suitable driver found for jdbc:hive2://localhost:10000/default while connecting using jsp

I am trying to execute my java code using jsp.我正在尝试使用 jsp 执行我的 java 代码。 The code contains hive connection and few simple queries.代码包含 hive 连接和一些简单的查询。 When I just run the java code it is executing properly, but when executing using jsp it shows the error in the title.当我只运行 java 代码时,它执行正常,但是在使用 jsp 执行时,它在标题中显示错误。

java code代码

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import org.apache.hive.jdbc.HiveDriver;
public class Hive {
public void hive1() throws SQLException {

try{

String driverName = "org.apache.hive.jdbc.HiveDriver";

Connection conn = DriverManager.getConnection(
"jdbc:hive2://localhost:10000/default", "hduser", "abc");

System.out.println("Connected");
Statement stmt = conn.createStatement();

stmt.execute("CREATE TABLE IF NOT EXISTS "
+" tweets5 ( id BIGINT, created_at STRING, "
+"source STRING, "
+"favorited BOOLEAN, "
+" retweet_count INT,"
+"retweeted_status STRUCT< "
+"text:STRING, "
+" user:STRUCT<screen_name:STRING,name:STRING>,"
+"retweet_count:INT>, "
+" entities STRUCT< "
+"urls:ARRAY<STRUCT<expanded_url:STRING>>, "
+"user_mentions:ARRAY<STRUCT<screen_name:STRING,name:STRING>>, "
+" hashtags:ARRAY<STRUCT<text:STRING>>>,"
+" text STRING,"
+" user STRUCT<"
+"screen_name:STRING, "
+"name:STRING, "
+"locations:STRING, "
+"friends_count:INT, " 
+" followers_count:INT,"
+"statuses_count:INT, "
+"verified:BOOLEAN, "
+"utc_offset:INT, "
+"time_zone:STRING>, "
+ " in_reply_to_screen_name STRING)"
+" ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'"
+" LOCATION '/user/flume/tweets'");
System.out.println("Table created successfully");


String sql = "describe tweets5";
ResultSet res = stmt.executeQuery(sql);
while (res.next()) 
{      
    System.out.println(res.getString(1) + "\t" + res.getString(2));
}



sql = "select id,user.name from tweets5";
System.out.println("\nRunning: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(String.valueOf(res.getString(1)) + "\t" +     String.valueOf(res.getString(2)));
}
}
System.out.println("Operation done successfully.");
stmt.close();
conn.close();

System.out.println("End");
}catch(SQLException se){
se.printStackTrace();
}

catch(Exception e){
e.printStackTrace();
}
}
/*
public static void main(String[] args) throws SQLException {

Hive h = new Hive();
h.hive1();
}
*/
}

jsp code代码

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"     pageEncoding="ISO-8859-1"%>

<%@ page import="hive.Hive" %>

<%@ page import="java.util.*"%>

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.DriverManager"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.sql.SQLException"%>
<%@ page import="java.sql.Statement"%>
<%@ page import="java.sql.*"%>
<%@ page import="org.apache.hive.jdbc.HiveDriver" %>

<!DOCTYPE html>
<html>
<head>

    <title>page4</title>
</head>
<body>


   <% 

   Hive h = new Hive();
   h.hive1();

   %>

   <%= "<h1> Processing started....</h1>" %>


</body>
</html>

You declare "driverName", but never use it.您声明“driverName”,但从不使用它。

Try adding:尝试添加:

try {
      Class.forName(driverName);
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      System.exit(1);
    }

(From https://community.hortonworks.com/articles/25410/simple-steps-to-test-hive-jdbc-connect.html ) (来自https://community.hortonworks.com/articles/25410/simple-steps-to-test-hive-jdbc-connect.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.sql.SQLException:没有为jdbc找到合适的驱动程序:hive:// localhost:10000 / default - java.sql.SQLException: No suitable driver found for jdbc:hive://localhost:10000/default JAVA 10-java.sql.SQLException:找不到适用于jdbc:mysql:// localhost:3306 /错误的驱动程序 - JAVA 10 - java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/ error java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mydatabase Android Studio Java MySQL - java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mydatabase Android Studio Java MySQL java.sql.SQLException:没有为jdbc找到合适的驱动程序:derby:// localhost:1527 / Employees1 - java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/Employees1 引起:java.sql.SQLException:没有为jdbc找到合适的驱动程序:mysql:// localhost:3306 / domain - Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/domain java.sql.SQLException:找不到适用于jdbc:sqlite的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc:sqlite java.sql.SQLException:找不到适用于jdbc:microsoft的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc:microsoft java.sql.SQLException:找不到适合jdbc的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc 错误:java.sql.SQLException:未找到适合jdbc:sqlserver的驱动程序 - Error: java.sql.SQLException: No suitable driver found for jdbc:sqlserver java.sql.SQLException:找不到合适的驱动程序jdbc:oracle:thin - java.sql.SQLException: No suitable driver found jdbc:oracle:thin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM