whitePlay 2017-06-15 08:22 采纳率: 0%
浏览 2031

用jdbc连接hive时resultset里面查不到数据,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;
        }
    }
}

}

  • 写回答

1条回答 默认 最新

  • 丵鹰 2017-06-15 08:42
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站