Java JDBC Hive客户端不满足请求,但也未遇到错误 [英] Java JDBC Hive client does not fulfill request, but does not experience error either

查看:240
本文介绍了Java JDBC Hive客户端不满足请求,但也未遇到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下Java代码:

I have this Java code:

import org.apache.log4j.*;
import java.sql.*;
import static spark.Spark.*;

public class App {

    final static Logger logger = Logger.getLogger(App.class);

    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        BasicConfigurator.configure(); // configure log4j
        Class.forName("org.apache.hive.jdbc.HiveDriver");

        System.out.println("Trying to connect!");
        Connection con = DriverManager.getConnection("jdbc:hive2://xxx-edge-lb01:9897",
                "hdpair", "foobar");
        System.out.println("Connected!");
        Statement stmt = con.createStatement();
        String sql = ("show tables");
        System.out.println("Trying to execute query!");
        ResultSet res = stmt.executeQuery(sql);
        System.out.println("Query executed!");

        if (res.next()) {
            System.out.println(res.getString(1));
        } else {
            System.out.println("Could not connect!");
        }

    }

}

启动时,我得到以下信息:

when it starts up, I get the following:

[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ cdt-hive ---
0 [cdt.App.main()] WARN cdt.App  - This is warn.
Trying to connect!
36 [cdt.App.main()] INFO org.apache.hive.jdbc.Utils  - Supplied authorities: hdprd1-edge-lb01:8888
36 [cdt.App.main()] INFO org.apache.hive.jdbc.Utils  - Resolved authority: hdprd1-edge-lb01:8888
137 [cdt.App.main()] INFO org.apache.hive.jdbc.HiveConnection  - Will try to open client transport with JDBC Uri: jdbc:hive2://hdprd1-edge-lb01:8888
138 [cdt.App.main()] DEBUG org.apache.thrift.transport.TSaslTransport  - opening transport org.apache.thrift.transport.TSaslClientTransport@4ba8c455
217 [cdt.App.main()] DEBUG org.apache.thrift.transport.TSaslClientTransport  - Sending mechanism name PLAIN and initial response of length 23
219 [cdt.App.main()] DEBUG org.apache.thrift.transport.TSaslTransport  - CLIENT: Writing message with status START and payload length 5
219 [cdt.App.main()] DEBUG org.apache.thrift.transport.TSaslTransport  - CLIENT: Writing message with status COMPLETE and payload length 23
219 [cdt.App.main()] DEBUG org.apache.thrift.transport.TSaslTransport  - CLIENT: Start message handled
219 [cdt.App.main()] DEBUG org.apache.thrift.transport.TSaslTransport  - CLIENT: Main negotiation loop complete
219 [cdt.App.main()] DEBUG org.apache.thrift.transport.TSaslTransport  - CLIENT: SASL Client receiving last message

问题在于它永远不会到达

The problem is that it never reaches

 System.out.println("Connected!");

System.out.println("Trying to execute query!");

推荐答案

这是我用来捕获JDBC的静默安全异常的代码段.可能会对您的情况有所帮助.

This is the code snippet that I use to trap silent security exceptions with JDBC. Could prove helpful in your case.

// no specific handling of connection failures, these are not recoverable anyway
// EXCEPT for the silent "SecurityException" failures that must be exposed
try
{ cnx =DriverManager.getConnection(jdbcUrl, jdbcLogin, jdbcPwd) ; }
catch (SecurityException xx)
{ throw new IllegalStateException("Caught silent SecurityException\n" +xx.getMessage()) ; }

这篇关于Java JDBC Hive客户端不满足请求,但也未遇到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆