java通过jdbc连接impala

  1、所需 jar 包

    hive_metastore.jar,hive_service.jar,httpclient-4.4.1.jar,httpcore-4.4.1.jar,

    ImpalaJDBC41.jar,libfb303-0.9.0.jar,libthrift-0.9.0.jar,ql.jar,

    slf4j-api-1.7.7.jar,TCLIServiceClient.jar,zookeeper-3.4.6.jar

    

  2、测试代码

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author:
 * @Description:
 * @Date:Created in 15:48 2018/8/29
 * @Modified by:
 **/
public class test_jdbc {
    public static void test(){
        Connection con = null;
        ResultSet rs = null;
        PreparedStatement ps = null;
        String JDBC_DRIVER = "com.cloudera.impala.jdbc41.Driver";
        String CONNECTION_URL = "jdbc:impala://192.168.2.20:21050";

        try
        {
            Class.forName(JDBC_DRIVER);
            con = (Connection) DriverManager.getConnection(CONNECTION_URL);
            ps = con.prepareStatement("select count(*) from billdetail;");
            rs = ps.executeQuery();
            while (rs.next())
            {
                System.out.println(rs.getString(1) );
            }
        } catch (Exception e)
        {
            e.printStackTrace();
        } finally
        {
            try {
                rs.close();
                ps.close();
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {
        test();
    }
}

 

posted on 2018-08-29 16:14  shaomine  阅读(15355)  评论(1编辑  收藏  举报