案例: jdbc 操作hive数据库

1.依赖jar包:注意版本冲突的问题

hive-exec-0.13.1.jar

hive-jdbc-0.13.1.jar

hive-metastore-0.13.1.jar

hive-service-0.13.1.jar

hadoop-client-1.2.1.jar

hadoop-common-2.3.0.jar

 

2. 编写 jdbc 代码:

public class HiveJdbcTest {



    static {
        try {
            Class.forName("org.apache.hive.jdbc.HiveDriver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public static void main(String[] args) throws SQLException {
        try {
            Statement stmt = null;
            try {
                Connection con = DriverManager.getConnection("jdbc:hive2://hive数据库主机:hive数据库端口/hive数据库名称", "用户名", "密码");
                stmt = con.createStatement();
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }
            String createSQL = "create table table01(id string,name string )";
            boolean res = stmt.execute(createSQL);
            System.out.println("  createTableInHive: end exec !!    res:" + !res);

            // String sql =
            // "create view if not exists 库名.view03 (id ,name) comment '批量' as select id,name from 库名.table01";
            // System.out.println("Running3: " + sql);
            // boolean temp = stmt.execute(sql);
            // System.out.println("  createViewInHive: end exec !!    temp:" + !temp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值