-
pom.xml (来源: https://blog.csdn.net/niityzu/article/details/42639369)
<properties>
<hive-jdbc.version>1.2.1</hive-jdbc.version>
<hive-exec.version>1.2.1</hive-exec.version>
<hive-metastore.version>1.2.1</hive-metastore.version>
<hive-service.version>1.2.1</hive-service.version>
<libfb303.version>0.9.3</libfb303.version>
<hadoop-common.version>2.7.1</hadoop-common.version>
<httpclient.version>4.5.3</httpclient.version>
<httpcore.version>4.4.6</httpcore.version>
</properties><dependencies>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>{hive-exec.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-metastore</artifactId>
<version>{hive-service.version}</version>
</dependency>
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libfb303</artifactId>
<version>{hadoop-common.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>{httpcore.version}</version>
</dependency>
</dependencies> -
代码
public class HiveUtil {public static Connection getHiveCon() throws ClassNotFoundException, SQLException {
Connection connection = null;
Class.forName("org.apache.hive.jdbc.HiveDriver");
connection = DriverManager.getConnection("jdbc:hive2://ip:21050/;auth=noSasl", "账号", "");
return connection;
}public static void main(String[] args) throws SQLException, ClassNotFoundException {
Statement stmt = HiveUtil.getHiveCon().createStatement();
String sql = " select count(*) from 数据库.表 WHERE dt='20190304' ";
String rest = "";
ResultSet res = stmt.executeQuery(sql);
while (res.next()) {
rest = res.getString(1);
System.out.println(rest);
}
}
}
网友评论