zoukankan      html  css  js  c++  java
  • jdbc连接hive0.14

    Jdbc连接hive0.14版本号

    眼下官网最新版本号是hive0.13,要想下载最新的hive得去git上去clone一个。

    Hive0.14最大特点是支持直接插入。

    如今做一个jdbc连接hive0.14的样例。

    须要的jar包:

     

    不要去引入单独的一个集成hivejar由于那个包括了tomcat里面的几个jar包。

    当建立hiveproject时。会冲突导致hive的集成包载入不上。

    1.hive连接的工具类:

    package com.fish;

    import java.sql.Connection;

    import java.sql.DriverManager;

    import java.sql.PreparedStatement;

    import java.sql.ResultSet;

    import java.sql.SQLException;

    import java.util.ResourceBundle;

    /**

     * 连接数据库的工具类,被定义成不可继承且是私有訪问

     */

    public final class DBTool {

    final private static String OPTION_FILE_NAME = "hivedatabase";

    private static Connection conn;

    static ResourceBundle res;

    static {

    res = ResourceBundle.getBundle(OPTION_FILE_NAME);

    try {

    String driver = res.getString("jdbc.driver");

    Class.forName(driver);

    catch (ClassNotFoundException e) {

    e.printStackTrace();

    throw new RuntimeException(e);

    }

    }

    /**

     * 获取数据库的连接

     * 

     * @return conn

     */

    public static Connection getConnection() {

    if (null == conn) {

    try {

    String url = res.getString("jdbc.url");

    String user = res.getString("jdbc.username");

    String password = res.getString("jdbc.password");

    conn = DriverManager.getConnection(url, user, password);

    catch (SQLException e) {

    e.printStackTrace();

    throw new RuntimeException(e);

    }

    }

    return conn;

    }

    /**

     * 释放资源

     * 

     * @param conn

     * @param pstmt

     * @param rs

     */

    public static void closeJDBC(Connection conn, PreparedStatement pstmt,

    ResultSet rs) {

    if (null != rs) {

    try {

    rs.close();

    catch (SQLException e) {

    e.printStackTrace();

    throw new RuntimeException(e);

    finally {

    if (null != pstmt) {

    try {

    pstmt.close();

    catch (SQLException e) {

    e.printStackTrace();

    throw new RuntimeException(e);

    finally {

    if (null != conn) {

    try {

    conn.close();

    catch (SQLException e) {

    e.printStackTrace();

    throw new RuntimeException(e);

    }

    }

    }

    }

    }

    }

    }

    }

    2.hivedatabase.properties

    #hive database setting

    jdbc.type=hive

    jdbc.driver=org.apache.hive.jdbc.HiveDriver

    jdbc.url=jdbc:hive2://192.168.2.150:10000/default

    jdbc.username=hadoop

    jdbc.password=

    3.test是类

    public class Test {

    public static void main(String[] args) throws Exception {

    Connection connection = DBTool.getConnection();

    System.out.println(connection);}

    }

    假设能连接通说明你已经成功连接上hive了。

  • 相关阅读:
    ASCII、Unicode和UTF-8等常见字符编码格式介绍
    pycharm创建脚本头文件模板
    pycharm常用设置项和快捷键
    Genymotion安装apk问题
    [Android测试] Appium的一些坑问题错误解决 与 技巧集锦
    Appium+python自动化测试过程中问题
    python客户端和Appium服务端联调出现的问题解决办法
    移动端自动化测试环境搭建
    "http://127.0.0.1:4723/wd/hub"的解释
    wireshark抓包看ECN
  • 原文地址:https://www.cnblogs.com/llguanli/p/6741774.html
Copyright © 2011-2022 走看看