JavaJDBC配置单元客户端没有完成请求,但也没有遇到错误

4uqofj5v  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(369)

我有以下java代码:

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!");
        }

    }

}

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

[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

问题是它永远达不到

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

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

r3i60tvu1#

这是我用来捕获jdbc静默安全异常的代码片段。可能对你有帮助。

// 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()) ; }

相关问题