【问题标题】:Copy ResultSet without using CachedRowSetImpl.execute()不使用 CachedRowSetImpl.execute() 复制 ResultSet
【发布时间】:2009-07-20 01:11:04
【问题描述】:

我试图在执行查询后关闭连接。之前,我只创建了一个CachedRowSetImpl 实例,它会为我释放资源。但是,我正在使用来自 Hadoop 项目的 Hive 数据库驱动程序。它不支持CachedRowSetImpl.execute()。我想知道是否有任何其他方法可以让我复制ResultSet 对象并关闭连接?

【问题讨论】:

    标签: java hadoop resultset hive cachedrowset


    【解决方案1】:

    您可以从现有的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();            
        }       
    }
    

    【讨论】:

    • 也使用 hive,我在 .populate 调用中收到“方法不支持”错误。
    猜你喜欢
    • 2015-12-22
    • 2010-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    • 2023-03-05
    • 2021-06-22
    相关资源
    最近更新 更多