Java 不使用CachedRowSetImpl.execute()复制结果集

Java 不使用CachedRowSetImpl.execute()复制结果集,java,hadoop,resultset,hive,cachedrowset,Java,Hadoop,Resultset,Hive,Cachedrowset,我正在尝试在执行查询后关闭连接。之前,我只创建了一个CachedRowSetImpl实例,它将负责为我释放资源。不过,我使用的是Hadoop项目中的Hive数据库驱动程序。它不支持CachedRowSetImpl.execute()。我想知道是否有其他方法允许我复制结果集对象并关闭连接?您可以从现有的结果集填充缓存集: public static RowSet executeQuery(String sql) throws Exception { Connection con = nul

我正在尝试在执行查询后关闭连接。之前,我只创建了一个
CachedRowSetImpl
实例,它将负责为我释放资源。不过,我使用的是Hadoop项目中的Hive数据库驱动程序。它不支持
CachedRowSetImpl.execute()
。我想知道是否有其他方法允许我复制
结果集
对象并关闭连接?

您可以从现有的
结果集
填充
缓存集

public static RowSet executeQuery(String sql) throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try{
        con = openConnection();
        ps = con.prepareStatement(sql);
        rs = ps.executeQuery();
        CachedRowSet rows = new CachedRowSetImpl();
        rows.populate(rs);
        return rows;
    }finally{
        rs.close();
        ps.close();
        con.close();            
    }       
}

您可以从现有的
ResultSet
填充
CachedRowSet

public static RowSet executeQuery(String sql) throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try{
        con = openConnection();
        ps = con.prepareStatement(sql);
        rs = ps.executeQuery();
        CachedRowSet rows = new CachedRowSetImpl();
        rows.populate(rs);
        return rows;
    }finally{
        rs.close();
        ps.close();
        con.close();            
    }       
}

同时使用配置单元,我在.populate调用上得到一个“method not supported”错误。同时使用配置单元,我在.populate调用上得到一个“method not supported”错误。