用JDBC连接Impala

1.下载所需要的架包

     http://download.csdn.net/detail/qq_36611929/9894733

本人导入所有架包出错,所以就删掉了slf4j-api-1.5.11.jar、slf4j-log4j12-1.5.11.jar、log4j-1.2.14.jar三个包

2.编写JDBC,并测试是否连接成功

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

public class ImpalaDao {
    private static String DRIVER = "com.cloudera.impala.jdbc41.Driver";
    private static String URL = "jdbc:impala://xxxxxxx:21050/DataBaseName";
    public static void main(String[] args) {
        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement pst = null;


        try {
            Class.forName(DRIVER);
            conn = DriverManager.getConnection(URL);
            pst = conn.prepareStatement("select * from userinfo");
            rs = pst.executeQuery();
            while (rs.next()) {
                System.out.println(rs.getString(1) );
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                conn.close();
                pst.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

你可能感兴趣的:(impala,JDBC)