我有这个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!");
答案 0 :(得分:0)
这是我用于使用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()) ; }