love_Java123
love_Java123
2017-06-15 08:20

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

5
  • hive
  • jdbc
  • url

代码如下:
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;
    }
}

}
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答