【Hadoop】Hive开发手册(JavaAPI)

文章目录

  • 前言
  • 装备
  • Core
    • Hive开启远程服务
    • Maven依赖
    • Result
  • Github
  • Author

前言

hadoop系列

  1. 【Hadoop】Hadoop完全分布式集群搭建 https://blog.csdn.net/HuHui_/article/details/83960047
  2. 【Hadoop】Hive搭建 https://blog.csdn.net/HuHui_/article/details/84202077
  3. 【Hadoop】Hdfs开发手册(JavaAPI)https://blog.csdn.net/HuHui_/article/details/83834199

这篇文章感觉有划水…因为直接使用Hive的JavaAPI用的不多。本人一般项目更多是用spark-hive。感兴趣的可以看看【Spark】SparkSql分析结果写入Mysql

https://blog.csdn.net/HuHui_/article/details/83964233

Hive和HDFS应用更多在服务器上。使用系统调度。但也要对Java的JDBC调用Hive要了解。

因为后面会把Hive和HDFS详细shell 命令和实际应用做一个总结blog。

现在是过度篇。

装备

  1. Hadoop环境
  2. Hive环境
  3. Maven依赖
  4. sql基础

Core

JDBC相信大家学过Java都是一个基础。Hive抽象出接口,提供JDBC连接。

HIVE-JDBC其实本质上是扮演一个协议转换的角色,把jdbc的标准协议转换为访问HiveServer服务的协议.

Hive开启远程服务

# hive --service hiveserver & 

Maven依赖

<hadoop.version>2.6.5hadoop.version>
<hive.version>2.1.0hive.version>

<dependency>
        <groupId>org.apache.hivegroupId>
        <artifactId>hive-jdbcartifactId>
        <version>${hive.version}version>
 dependency>

Java连接Hive代码

/**
 * HiveJDBC
 * 

* Description: *

* Creation Time: 2018/11/19 22:08. * * @author Hu Weihui */ public class HiveJDBC { /** * The constant driverName. * * @since hui_project 1.0.0 */ private static final String driverName ="org.apache.hive.jdbc.HiveDriver"; /** * The constant url. * * @since hui_project 1.0.0 */ private static final String url="jdbc:hive2://192.168.31.60:10000/default"; /** * application. * * @param args the input arguments * @throws SQLException the sql exception * @throws ClassNotFoundException the class not found exception * @since hui_project 1.0.0 */ public static void main(String[] args) throws SQLException, ClassNotFoundException { Class.forName(driverName); Connection connection = DriverManager.getConnection(url, "root", "123456"); Statement statement = connection.createStatement(); statement.execute("CREATE DATABASE d_huweihui"); connection.close(); } /** * 创建数据库. * * @param statement the statement * @throws SQLException the sql exception * @since hui_project 1.0.0 */ public void createDataBases(Statement statement) throws SQLException { String sql = "CREATE DATABASE d_huweihui"; statement.execute(sql); } /** * 查看数据库. * * @param statement the statement * @throws SQLException the sql exception * @since hui_project 1.0.0 */ public void showDataBases(Statement statement) throws SQLException { String sql = "show databases"; ResultSet resultSet = statement.executeQuery(sql); while (resultSet.next()){ System.out.println(resultSet.getString(1)); } } }

Result

【Hadoop】Hive开发手册(JavaAPI)_第1张图片

Github

https://github.com/ithuhui/hui-base-java

在【hui-base-hadoop】- com.hui.base.hadoop.hive

Author

 作者:HuHui
 转载:欢迎一起讨论web和大数据问题,转载请注明作者和原文链接,感谢

你可能感兴趣的:(BigData,Developer,Manual)