第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

舉一個(gè)hive3 jdbc栗子

標(biāo)簽:
Hbase

以下使用的是kerberos认证模式进行连接

使用过程

导入jdbc

compile group: 'org.apache.hive', name: 'hive-jdbc', version: '3.0.0'

HiveTest.java

import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.security.UserGroupInformation;import org.junit.Before;import org.junit.Test;import java.sql.*;public class HiveTest {    private static String url = "jdbc:hive2://storm4.starsriver.cn:2181,storm2.starsriver.cn:2181,storm3.starsriver.cn:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2;";    private static String driverName ="org.apache.hive.jdbc.HiveDriver";    private static Connection conn;    private static PreparedStatement ps;    private static ResultSet rs;    @Before
    public void init() throws Exception {
        System.setProperty("java.security.krb5.conf", "/etc/krb5.conf");        final String user = "admin/admin@DEMO.COM";        final String keyPath = "/etc/security/keytabs/admin.keytab";

        Configuration conf = new Configuration();
        conf.addResource("hive-site.xml");
        conf.set("hbase.zookeeper.quorum", "host4.demo.com,host2.demo.com,host3.demo.com");
        conf.set("hadoop.security.authentication", "kerberos");

        UserGroupInformation.setConfiguration(conf);
        UserGroupInformation.loginUserFromKeytab(user, keyPath);
    }    public Connection getConnnection() {        try {
            Class.forName(driverName);
            conn = DriverManager.getConnection(url);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (SQLException e) {
            e.printStackTrace();
        }        return conn;
    }    public PreparedStatement prepare(Connection conn, String sql) {
        PreparedStatement ps = null;        try {
            ps = conn.prepareStatement(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }        return ps;
    }    public void getAll(String tablename) {
        conn=getConnnection();
        String sql="select * from "+tablename;
        System.out.println(sql);        try {
            ps=prepare(conn, sql);
            rs=ps.executeQuery();            int columns=rs.getMetaData().getColumnCount();            while(rs.next()) {                for(int i=1;i<=columns;i++) {
                    System.out.print(rs.getString(i));
                    System.out.print("\t\t");
                }
                System.out.println();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }    @Test
    public void testCount(){
        getAll("TEST_LOG");
    }
}

输出结果

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
select * from TEST_LOG1       lake        
2       lake1       
3       admin       
4       admin       

Process finished with exit code 0



作者:dounine
链接:https://www.jianshu.com/p/312a0feb0354


點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消