zoukankan      html  css  js  c++  java
  • hive使用

    package Main;
    
    
    
    import java.sql.SQLException;
    
    import java.sql.Connection;
    
    import java.sql.ResultSet;
    
    import java.sql.Statement;
    
    import java.sql.DriverManager;
    
    public class HiveJdbcClientv1 {
    
    private static String driverName = "org.apache.hive.jdbc.HiveDriver";
    
    /**
    
    * @param args
    
    * @throws SQLException
    
    */
    
    public static void main(String[] args) throws SQLException {
    
    try {
    
    Class.forName(driverName);
    
    } catch (ClassNotFoundException e) {
    
    // TODO Auto-generated catch block
    
    e.printStackTrace();
    
    System.exit(1);
    
    }
    
    //replace "hive" here with the name of the user the queries should run as
    
    Connection con = DriverManager.getConnection("jdbc:hive2://10.100.12.30:10000/default", "yjy_research", "research");
    
    Statement stmt = con.createStatement();
    
    stmt.execute("set mapreduce.job.queuename=root.yjy");
    
    stmt.execute("set hive.exec.dynamic.partition.mode=nonstrict");
    
    // show tables
    
    // String sql = "show tables '" + tableName + "'";
    
    String sql = ("select * from dp_ods.o_pl_crm_intopieces_dk_s where id = 'J3961' and etl_date='2017-06-12' limit 10");
    
    ResultSet res = stmt.executeQuery(sql);
    
    if (res.next()) {
    
    System.out.println("sonyshang");
    
    System.out.println(res.getString(1)+","+res.getString(2));
    
    }
    
    }
    
    }
    
    
    
    pom文件
    
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    
    <groupId>nerv.org</groupId>
    
    <artifactId>hive</artifactId>
    
    <version>0.0.1-SNAPSHOT</version>
    
    <packaging>jar</packaging>
    
    
    
    <name>hive</name>
    
    <url>http://maven.apache.org</url>
    
    
    
    <properties>
    
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    
    </properties>
    
    
    
    <dependencies>
    
    
    
    <dependency>
    
    <groupId>jdk.tools</groupId>
    
    <artifactId>jdk.tools</artifactId>
    
    <version>1.8</version>
    
    <scope>system</scope>
    
    <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
    
    </dependency>
    
    
    
    <dependency>
    
    <groupId>junit</groupId>
    
    <artifactId>junit</artifactId>
    
    <version>3.8.1</version>
    
    <scope>test</scope>
    
    </dependency>
    
    
    
    <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-jdbc -->
    
    <dependency>
    
    <groupId>org.apache.hive</groupId>
    
    <artifactId>hive-jdbc</artifactId>
    
    <version>2.0.0</version>
    
    </dependency>
    
    </dependencies>
    
    </project>
  • 相关阅读:
    洛谷——P1970 花匠
    洛谷—— P1969 积木大赛
    洛谷——P1966 火柴排队
    洛谷——P1965 转圈游戏
    python练习-跳出多层循环和购物车
    WinCE设置多国语言支持
    java开发环境搭建
    MCC(移动国家码)和 MNC(移动网络码)
    技术团队新官上任之基层篇
    技术团队新官上任之中层篇
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13312502.html
Copyright © 2011-2022 走看看