-
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);
}
}
}
连接hive查询
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。