Pro*_*mer 1 java hadoop hive resultset cachedrowset
我正在尝试在执行查询后关闭连接.之前,我只是创建一个CachedRowSetImpl实例,它将负责为我释放资源.但是,我正在使用Hadoop项目的Hive数据库驱动程序.它不支持CachedRowSetImpl.execute().我想知道是否有其他方式可以让我复制ResultSet对象并关闭连接?
您可以CachedRowSet从现有填充a ResultSet:
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();
}
}
Run Code Online (Sandbox Code Playgroud)