hadoop 3.3.1
Hive 2.3.9
hive-jdbc-2.3.9.jar
我已经开始蜂巢了。在 hive-site.xml 中:
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:derby:;databaseName=metastore_db;create=true</value>
<description>JDBC connect string for a JDBC metastore </description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>org.apache.derby.jdbc.EmbeddedDriver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>APP</value>
<description>Username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>mine</value>
<description>password to use against metastore database</description>
</property>
HiveCreateDb.java 文件:
public class HiveCreateDb {
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException {
// Register driver and create driver instance
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
// get connection
Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "APP", "mine");
Statement stmt = con.createStatement();
stmt.executeQuery("CREATE DATABASE userdb");
System.out.println("Database userdb created successfully.");
con.close();
}
}
我已经编译并运行了java文件
$ javac -classpath ../jars/hive-jdbc-2.3.9.jar HiveCreateDb.java -d .
$ java com.clx.bigdata.hive.HiveCreateDb
2021-07-09T10:56:12,300 INFO [main] org.apache.hive.jdbc.Utils - 提供的权限:localhost:10000
2021-07-09T10:56:12,321 INFO [main] org.apache.hive.jdbc。实用程序 - 已解决权限:localhost:10000
2021-07-09T10:56:13,210 WARN [main] org.apache.hive.jdbc.HiveConnection - 无法连接到 localhost:10000
线程“main”中的异常 java.sql.SQLException:无法使用 JDBC Uri 打开客户端传输:jdbc:hive2://localhost:10000/default: java.net.ConnectException: Connection denied (Connection denied)
at org.apache.hive.jdbc.HiveConnection.(HiveConnection.java:224 )
在 org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:107)
在 java.sql.DriverManager.getConnection(DriverManager.java:664)
在 java.sql.DriverManager.getConnection(DriverManager.java:247)
在 com.clx.bigdata.hive.HiveCreateDb.main(HiveCreateDb.java:21)
引起:org.apache.thrift.transport.TTransportException: java.net .ConnectException:
在 org.apache.thrift.transport.TSaslTransport.open(TSaslTransport.java:266)
的 org.apache.thrift.transport.TSocket.open(TSocket.java:226)的连接被拒绝(连接被拒绝)
。 apache.thrift.transport.TSaslClientTransport.open(TSaslClientTransport.java:37)
在 org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:311)
在 org.apache.hive.jdbc.HiveConnection.(HiveConnection.java :196)
... 4 更多
原因:java.net.ConnectException:连接被拒绝(连接被拒绝)
在 java.net.PlainSocketImpl.socketConnect(Native Method)
在 java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476)
在 java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218)
在 java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java:200)
在 java.net.SocksSocketImpl.connect(SocksSocketImpl.java:394)
在 java.net.Socket.connect(Socket.java:606)
在 org.apache.thrift.transport.TSocket.open( TSocket.java:221)
... 还有 8 个
我发现端口 10000 没有打开,当我检查时:
netstat -tln | grep 10000
有什么问题吗?