分享

org.apache.hive.service.cli.HiveSQLException: null

zstu 2018-5-22 17:20:54 发表于 异常错误 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 10 12363
我用jdbc连接hiveserver2,但出现了如下异常:hive版本1.2.1 beeline连接良好
[mw_shl_code=applescript,true]def main(args: Array[String]): Unit = {
    val driverName: String = "org.apache.hive.jdbc.HiveDriver"
    val Url: String = "jdbc:hive2://node1:10000/" //填写hive的IP,之前在配置文件中配置的IP
    var conn: Connection = null
    Class.forName(driverName)
    conn = DriverManager.getConnection(Url,"root","123456")

    var ps: PreparedStatement = null
    ps = conn.prepareStatement("show databases")

    val set = ps.executeQuery()
    while (set.next()) {
      println(set.getString(0))
    }

  }[/mw_shl_code]
[mw_shl_code=applescript,true]Exception in thread "main" org.apache.hive.service.cli.HiveSQLException
        at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:256)
        at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:247)
        at org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:586)
        at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:192)
        at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:247)
        at com.test.env.metaschema.HiveServer2TestMain$.main(HiveServer2TestMain.scala:12)
        at com.test.env.metaschema.HiveServer2TestMain.main(HiveServer2TestMain.scala)
Caused by: org.apache.hive.service.cli.HiveSQLException: null
        at org.apache.hive.service.cli.session.HiveSessionImpl.<init>(HiveSessionImpl.java:109)
        at org.apache.hive.service.cli.session.SessionManager.openSession(SessionManager.java:252)
        at org.apache.spark.sql.hive.thriftserver.SparkSQLSessionManager.openSession(SparkSQLSessionManager.scala:70)
        at org.apache.hive.service.cli.CLIService.openSession(CLIService.java:194)
        at org.apache.hive.service.cli.thrift.ThriftCLIService.getSessionHandle(ThriftCLIService.java:365)
        at org.apache.hive.service.cli.thrift.ThriftCLIService.OpenSession(ThriftCLIService.java:257)
        at org.apache.hive.service.cli.thrift.TCLIService$Processor$OpenSession.getResult(TCLIService.java:1253)
        at org.apache.hive.service.cli.thrift.TCLIService$Processor$OpenSession.getResult(TCLIService.java:1238)
        at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
        at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
        at org.apache.hive.service.auth.TSetIpAddressProcessor.process(TSetIpAddressProcessor.java:56)
        at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:285)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:748)[/mw_shl_code]

已有(10)人评论

跳转到指定楼层
langke93 发表于 2018-5-22 20:23:11
改成下面形式试试:
Connection conn = DriverManager.getConnection(jdbcurl,username,password);
Statement st = conn.createStatement();            
st.executeQuery("select * from table");
其实还可以通过其它形式连接,thrift很容易的。

更多参考
spark SQL Running the Thrift JDBC/ODBC server
http://www.aboutyun.com/forum.php?mod=viewthread&tid=17882


回复

使用道具 举报

zstu 发表于 2018-5-23 09:24:44
langke93 发表于 2018-5-22 20:23
改成下面形式试试:
Connection conn = DriverManager.getConnection(jdbcurl,username,password);
St ...

还是那个问题,它就是在DriverManager.getConnection(jdbcurl,username,password)这一行就报那个错,获取不到链接
回复

使用道具 举报

easthome001 发表于 2018-5-23 10:53:48
本帖最后由 easthome001 于 2018-5-23 11:01 编辑
zstu 发表于 2018-5-23 09:24
还是那个问题,它就是在DriverManager.getConnection(jdbcurl,username,password)这一行就报那个错,获取 ...

那就不是代码问题了。多从外部环境找问题。比如版本,包引入依赖等
引入的依赖比如下面

[mw_shl_code=bash,true]import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
[/mw_shl_code]

相关包
下面是hadoop2.2.等的,楼主找到对应包
[mw_shl_code=bash,true]hadoop-2.2.0/share/hadoop/common/hadoop-common-2.2.0.jar
$HIVE_HOME/lib/hive-exec-0.11.0.jar
$HIVE_HOME/lib/hive-jdbc-0.11.0.jar
$HIVE_HOME/lib/hive-metastore-0.11.0.jar  
$HIVE_HOME/lib/hive-service-0.11.0.jar   
$HIVE_HOME/lib/libfb303-0.9.0.jar   
$HIVE_HOME/lib/commons-logging-1.0.4.jar  
$HIVE_HOME/lib/slf4j-api-1.6.1.jar[/mw_shl_code]





回复

使用道具 举报

zstu 发表于 2018-5-23 11:11:56
easthome001 发表于 2018-5-23 10:53
那就不是代码问题了。多从外部环境找问题。比如版本,包引入依赖等
引入的依赖比如下面

这是引入的包,版本都跟线上一致了[mw_shl_code=applescript,true]<dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-jdbc</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-metastore</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-exec</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.6.0-cdh5.7.0</version>
        </dependency>[/mw_shl_code]
回复

使用道具 举报

hello2018 发表于 2018-5-23 11:35:06
zstu 发表于 2018-5-23 11:11
这是引入的包,版本都跟线上一致了[mw_shl_code=applescript,true]
            org.apache.hive
      ...

哭啊,楼主竟然用的是Scala。
最好你用Java哦。官网都是Java版本的。

回复

使用道具 举报

hello2018 发表于 2018-5-23 11:38:56
[mw_shl_code=java,true]import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;

public class HiveJdbcClient {
  private static String driverName = "org.apache.hive.jdbc.HiveDriver";

  /**
   * @param args
   * @throws SQLException
   */
  public static void main(String[] args) throws SQLException {
      try {
      Class.forName(driverName);
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      System.exit(1);
    }
    //replace "hive" here with the name of the user the queries should run as
    Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "hive", "");
    Statement stmt = con.createStatement();
    String tableName = "testHiveDriverTable";
    stmt.execute("drop table if exists " + tableName);
    stmt.execute("create table " + tableName + " (key int, value string)");
    // show tables
    String sql = "show tables '" + tableName + "'";
    System.out.println("Running: " + sql);
    ResultSet res = stmt.executeQuery(sql);
    if (res.next()) {
      System.out.println(res.getString(1));
    }
       // describe table
    sql = "describe " + tableName;
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);
    while (res.next()) {
      System.out.println(res.getString(1) + "\t" + res.getString(2));
    }

    // load data into table
    // NOTE: filepath has to be local to the hive server
    // NOTE: /tmp/a.txt is a ctrl-A separated file with two fields per line
    String filepath = "/tmp/a.txt";
    sql = "load data local inpath '" + filepath + "' into table " + tableName;
    System.out.println("Running: " + sql);
    stmt.execute(sql);

    // select * query
    sql = "select * from " + tableName;
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);
    while (res.next()) {
      System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
    }

    // regular hive query
    sql = "select count(1) from " + tableName;
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);
    while (res.next()) {
      System.out.println(res.getString(1));
    }
  }
}[/mw_shl_code]
地址https://cwiki.apache.org/conflue ... Server2Clients-JDBC
回复

使用道具 举报

hello2018 发表于 2018-5-23 11:42:48
本帖最后由 hello2018 于 2018-5-23 11:49 编辑

Scala通过jdbc也是可以。最好还是通过thrift连接。
回复

使用道具 举报

zstu 发表于 2018-5-23 13:39:49
hello2018 发表于 2018-5-23 11:42
Scala通过jdbc也是可以。最好还是通过thrift连接。

换成java的还是一样
回复

使用道具 举报

langke93 发表于 2018-5-23 17:45:48
zstu 发表于 2018-5-23 13:39
换成java的还是一样

你这已经不是代码问题了。无能为力。
回复

使用道具 举报

12下一页
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条