信息:用于 JDBC 连接的传输:null + Apache Hive
Posted
技术标签:
【中文标题】信息:用于 JDBC 连接的传输:null + Apache Hive【英文标题】:INFO: Transport Used for JDBC connection: null + Apache Hive 【发布时间】:2015-12-29 13:05:38 【问题描述】:我正在尝试通过 JDBC 连接 Apache Hive 和 Eclipse,但出现以下错误。以下是版本信息: Apache Hadoop:2.7.1,Hive:1.2.1 和 Eclipse Kepler。
****Error :****
Dec 29, 2015 6:04:00 PM org.apache.hive.jdbc.Utils parseURL
INFO: Supplied authorities: localhost:10000
Dec 29, 2015 6:04:00 PM org.apache.hive.jdbc.Utils parseURL
INFO: Resolved authority: localhost:10000
Dec 29, 2015 6:04:00 PM org.apache.hive.jdbc.HiveConnection openTransport
INFO: Will try to open client transport with JDBC Uri: jdbc:hive2://localhost:10000/default
Dec 29, 2015 6:04:00 PM org.apache.hive.jdbc.HiveConnection openTransport
INFO: Could not open client transport with JDBC Uri: jdbc:hive2://localhost:10000/default
Dec 29, 2015 6:04:00 PM org.apache.hive.jdbc.HiveConnection openTransport
INFO: Transport Used for JDBC connection: null
Exception in thread "main" java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://localhost:10000/default: java.net.ConnectException: Connection refused
at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:231)
at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:176)
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at test.JDBCtest.main(JDBCtest.java:25)
Caused by: org.apache.thrift.transport.TTransportException: java.net.ConnectException: Connection refused
at org.apache.thrift.transport.TSocket.open(TSocket.java:187)
at org.apache.thrift.transport.TSaslTransport.open(TSaslTransport.java:266)
at org.apache.thrift.transport.TSaslClientTransport.open(TSaslClientTransport.java:37)
at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:204)
... 5 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.thrift.transport.TSocket.open(TSocket.java:182)
... 8 more
代码:
package test;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class JDBCtest
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException,
try
Class.forName(driverName);
catch (ClassNotFoundException e)
e.printStackTrace();
System.exit(1);
Connection con =DriverManager.getConnection
("jdbc:hive2://localhost:10000/default","","");
System.out.println("Connected");
Statement stmt = con.createStatement();
String tableName = "testHiveDriverTable";
stmt.executeQuery("drop table " + tableName);
ResultSet res =
stmt.executeQuery("create table "+tableName+"(key int,value);
String sql = "show tables '" + tableName + "'";
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
if (res.next())
System.out.println(res.getString(1));
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));
String filepath = "/tmp/a.txt";
sql="load data local inpath'"+filepath + "' into table " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
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));
sql = "select count(1) from " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next())
System.out.println(res.getString(1));
请帮助解决我们长期以来面临的上述错误。 提前致谢 梅胡尔
【问题讨论】:
【参考方案1】:主要的例外是:
Caused by: java.net.ConnectException: Connection refused
您正在打开此行中没有用户名/密码的连接:
Connection con =DriverManager.getConnection("jdbc:hive2://localhost:10000/default","","");
请验证您的数据库的用户名和密码。
【讨论】:
感谢您的及时回复。我从“hive-default.xml.template”文件中添加了以下用户名和密码,但没有运气。仍然得到相同的错误日志。如果仍然缺少任何东西,请告诉我。用户名:APP 密码:mine Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "APP", "mine");以上是关于信息:用于 JDBC 连接的传输:null + Apache Hive的主要内容,如果未能解决你的问题,请参考以下文章
哪个套件 KahaDB 或现有的用于 activeMQ 的 JDBC?