2009-07-20 26 views
1

我試圖在執行查詢後關閉連接。以前,我只是創建一個CachedRowSetImpl實例,它會照顧爲我釋放資源。但是,我正在使用Hadoop項目中的Hive數據庫驅動程序。它不支持CachedRowSetImpl.execute()。我想知道是否有任何其他方式允許我複製ResultSet對象並關閉連接?複製ResultSet而不使用CachedRowSetImpl.execute()

回答

5

可以填充從現有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();    
    }  
} 
+0

使用蜂巢,以及和我得到「不支持方法」上的錯誤.populate調用。 – eych 2016-10-26 03:39:49

相關問題