【发布时间】:2009-07-20 01:11:04
【问题描述】:
我试图在执行查询后关闭连接。之前,我只创建了一个CachedRowSetImpl 实例,它会为我释放资源。但是,我正在使用来自 Hadoop 项目的 Hive 数据库驱动程序。它不支持CachedRowSetImpl.execute()。我想知道是否有任何其他方法可以让我复制ResultSet 对象并关闭连接?
【问题讨论】:
标签: java hadoop resultset hive cachedrowset
我试图在执行查询后关闭连接。之前,我只创建了一个CachedRowSetImpl 实例,它会为我释放资源。但是,我正在使用来自 Hadoop 项目的 Hive 数据库驱动程序。它不支持CachedRowSetImpl.execute()。我想知道是否有任何其他方法可以让我复制ResultSet 对象并关闭连接?
【问题讨论】:
标签: java hadoop resultset hive cachedrowset
您可以从现有的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();
}
}
【讨论】: