• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
小泽泽哒
博客园    首页    新随笔    联系   管理    订阅  订阅

JDBC:impala 连接DEMO

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;



public class JdbcTest {
   
    public static final String url = "jdbc:impala://10.133.235.42:21050/sqoop_test;SocketTimeOut=50";

    public static void main(String[] args) {
        
        try {
            test1();
        } catch (ClassNotFoundException e) {

            e.printStackTrace();
        }
    }

    public static void test1() throws ClassNotFoundException {
        boolean runable = false;
        int period = 0;

        String query = "select * from user ";
        try{
        Class.forName("com.cloudera.impala.jdbc41.Driver");
        }catch(Exception e){
            e.printStackTrace();
        }
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
      
        Long startTime = System.currentTimeMillis();
        try {
            Properties info = new Properties();
           
            conn = DriverManager.getConnection(url, "", "");

            startTime = System.currentTimeMillis();
            System.out.println("Connection Created");
            System.out.println(conn);
            int i = 0;

            st = conn.createStatement();
            rs = st.executeQuery(query);
            System.out.println(rs);
            while (rs.next()) {
                System.out.println(rs.getString(2));
            }

         
        } catch (Exception e) {
          
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
        Long endTime = System.currentTimeMillis();
        System.out.println("连接异常。连接维持时间:" + (endTime - startTime) / 1000 + "秒");
       
    }


}

 

jdbc:impala://10.133.235.42:21050/sqoop_test;SocketTimeOut=50

  地址:10.133.235.42 

  端口号:21050

  库名字:sqoop_test

  注意 使用jdbc:impala 连接的 时候,可以不使用用户名和密码。

  

   这样是可以访问 成功的。

☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*☆.。我是分隔符.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*☆.。.:*・°☆.。.:*・

 

最近总跟吾皇吵架,爱的多了,想要的就多了,心态就变了。

开始计较事情了,脾气变得好差,爱吃醋,爱比较,爱胡思乱想。不喜欢这样的自己。

 

 

有时候 好失望啊。。

posted @ 2018-03-29 14:36  小泽泽哒  阅读(3570)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3