• 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>
  • 相关阅读:
    PHP配置redis支持
    redis入门——redis常用命令
    CentOS7 linux下yum安装redis以及使用
    Linux安装配置git
    Java基础88 数据库设计的三大范式
    Java基础87 MySQL数据约束
    Java基础85 MVC开发模式
    错误/异常:java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind;的解决方法
    Java基础84 javaBean规范
    Java基础83 JSP标签及jsp自定义标签(网页知识)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13312502.html
Copyright © 2020-2023  润新知