用jdbc连hive时resultset里面没有结果,debug时rs里面的row值是null

用jdbc连hive时resultset里面没有结果,debug时rs里面的row值是null

问题描述:

代码如下:
public class ExtractJob {
public static void main(String[] args) {

String driverName = "org.apache.hive.jdbc.HiveDriver"; 
String url = "jdbc:hive2://***.***.***.***:10000/default";
Connection conn = null;
Statement state = null; 
ResultSet rs = null;




try {
    Class.forName(driverName);
    conn = DriverManager.getConnection(url,"hive","hive");
    state = conn.createStatement();





    state.execute("use test");
    rs = state.executeQuery("select * from test1");






    int columnCount = rs.getMetaData().getColumnCount();

    String str = "";
    while(rs.next()){
        for(int i = 0;i<columnCount;i++){
            str+=rs.getString(i);
        }
        System.out.println(str);
    }








} catch (SQLException e) {
    e.printStackTrace();
}catch (ClassNotFoundException e) {
    e.printStackTrace();
}finally{
    try {
        rs.close();
        state.close();
        conn.close();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }finally{
        rs = null;
        state = null;
        conn = null;
    }
}

}
}

你这里 String url = "jdbc:hive2://***.***.***.***:10000/default";连接的数据库是default;但在这里state.execute("use test");你把数据库切换到了test

hello!有人遇见过吗?

1.确认你连接的库下存在你访问的表
2.确认你的表中有数据
3.columnCount应该从第1列开始,而不是0开始