hadoop 3.3.1
Hive2.3.9
hive-jdbc-2.3.9.jar
我已经开始做Hive了。在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:12300信息[main]org.apache.hive.jdbc.utils-提供的权限:localhost:10000
2021-07-09t10:56:12321信息[main]org.apache.hive.jdbc.utils-解析权限:localhost:10000
2021-07-09t10:56:13210警告[main]org.apache.hive.jdbc.hiveconnection-无法连接到本地主机:10000
线程“main”java.sql.sqlexception中的异常:无法使用jdbc uri打开客户端传输:jdbc:hive2://localhost:10000/default:java.net.connectexception:连接被拒绝(连接被拒绝)
位于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.ttTransportException:java.net.connectexception:连接被拒绝(连接被拒绝)
位于org.apache.thrift.transport.tsocket.open(tsocket.java:226)
位于org.apache.thrift.transport.tsasltransport.open(tsasltransport.java:266)
位于org.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(本机方法)
位于java.net.abstractplainsocketimpl.doconnect(abstractplainsocketimpl.java:476)
位于java.net.abstractplainsocketimpl.connecttoaddress(abstractplainsocketimpl.java:218)
位于java.net.abstractplainsocketimpl.connect(abstractplainsocketimpl.java:200)
位于java.net.socksocketimpl.connect(socksocketimpl.java:394)
位于java.net.socket.connect(socket.java:606)
位于org.apache.thrift.transport.tsocket.open(tsocket.java:221)
... 8个以上
当我检查时,发现端口10000未打开:
netstat-tln | grep 10000
有什么问题吗?
暂无答案!
目前还没有任何答案,快来回答吧!