import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestHive {
// hive --service hiveserver2 --hiveconf hive.server2.thrift.port=10001
// if you want to change a port to start the hive2, then add the parameters
// private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
// this driver class is for hive, not hive2. please be noted
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException {
try {
Class.forName(driverName);
Connection con = DriverManager.getConnection("jdbc:hive2://192.168.1.50:10001/default",
"hadoop", "");
Statement stmt = con.createStatement();
String sql1 = "show tables";
String sql2 = "show databases";
String sql3 = "select count(1) from hive_user_info";
ResultSet rs = stmt.executeQuery(sql1);
while(rs.next()){
String s = rs.getString(1);
System.out.println(s);
}
con.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
ps:
the jdbc user should have permission of the hive execution. or it will fail.
分享到:
相关推荐
hive-jdbc
hive-jdbc-2.1.0.jar
hive-jdbc-1.2.1-standalone.jar hive-jdbc驱动jar包,欢迎下载
hive jdbc jar包用于hive连接数据库驱动
dbeaver连接hive时需要的驱动包hive-jdbc-uber-2.6.5.0-292.jar
hive-jdbc-uber-2.6.5.0-292.jar DbVisualizer (as of version 9.5.5) Below is an example configuration using DbVisualizer: Open the Diver Manager dialog ("Tools" > "Driver Manager...") and hit the ...
hive连接jdbc的jar包: hive-jdbc-1.1.0.jar
jdbc连接hive所需的一个包 ( hive-jdbc-3.1.2.jar)
hive-jdbc-3.1.2-standalone适用于linux
通过导入jar包,连接hive数据库驱动,DbVisualizer连接Hive数据库所需jar包,包含:hadoop-common-2.2.0.jar,hive-jdbc-2.1.1-standalone.jar,hive-jdbc-2.1.1.jar,满足日常hive查询需求。
hive版本匹配的驱动,该驱动可以在hive的jdbc目录下找到
Hive-jdbc-3.1.1.zip hive jdbc,用于大数据 hive 开发和数据库连接。
Hive连接的jar包——hive-jdbc-3.1.2-standalone.jar,使用数据库连接软件连接数据仓库时需要使用相应的驱动器驱动,希望对大家有所帮助
hive-jdbc-2.3.7-standalone,可用dbeaver连接hive数据库,在工具中进行数据库记录的新增改查
用java连接hive所必须的jar包,包括hadoop-commmon-2.6.4以及hive-jdbc-1.2.1-standalone
hive-jdbc-2.1.1.jar
hive-jdbc-2.1.1-cdh6.2.0(ieda等jdbc链接hive2.1.1);cdh6.2.0安装的hive2.1.1
hive-jdbc-uber-2.6.5.0-292.jar 驱动下载,hive-jdbc-uber-2.6.5.0-292.jar,hive-jdbc-uber-2.6.5.0-292.jar
hive-jdbc-uber-2.6.5.0-292.jar驱动
hive jdbc 3.1.0 jar