我正在尝试使用jdbc将hive数据库连接到java但是收到 connection refused 错误 . 我已经添加了所有需要的jar文件 . 我已经尝试了在线提供的所有可能的解决方案,包括 nohup hive --service hiveserver -p 10001 ,如果我们已经在某处使用了localhost:10000就完成了 . Hadoop已经开始在后台进行hive连接 . 我的代码:
import java.sql.*;
public class ConnectToHive{
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
private static Connection con=null;
private static Statement stmt=null;
public static void main(String[] args) throws SQLException
{
try {
Class.forName(driverName);
con= DriverManager.getConnection("jdbc:hive://localhost:10000/default","", "");
stmt = con.createStatement();
String tableName = "testHive";
stmt.execute("create table " + tableName + " (id int, name string)");
String sql = ("show tables");
ResultSet res = stmt.executeQuery(sql);
if (res.next()) {
System.out.println(res.getString(1));
}
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
请帮忙!提前致谢 .