jdbc连接Impala

之前因为kerberos原因,impala一直连接不上;尝试将kerberos关掉以后,impala连接成功。
jar包依赖:


image.png

CDH版本:5.15.1

package impala;

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

public class Impala4 {
    
     private static String driverName = "org.apache.hive.jdbc.HiveDriver";
     //"org.apache.hadoop.hive.jdbc.HiveDriver";


     public static void main(String[] args)throws SQLException {
            try {
                Class.forName(driverName);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
                System.exit(1);
            }       
            //这里的url是数据节点的ip,用户名和密码可以不写。
            Connection con = DriverManager.getConnection("jdbc:hive2://10.43.250.83:21050/;auth=noSasl");
            
            String sql = "select * from sjzx_dm.dm_td_gg limit 10";
            PreparedStatement ps = con.prepareStatement(sql);
            
            
            ResultSet res = ps.executeQuery();
            int col = res.getMetaData().getColumnCount();
            System.out.println("=====================================");
            while (res.next()){
                for(int i=1;i<=col;i++){
                    System.out.print(res.getString(i)+"\t");
                }
                System.out.print("\n");
            }
            System.out.println("=====================================");
     }
}

查询结果:
![DZR_{}`9KX_]ZIZ7VY(Z6R8.png](https://upload-images.jianshu.io/upload_images/15164067-64fab2504365f98a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

你可能感兴趣的:(jdbc连接Impala)