0
我試圖改善其選擇從HSQLDB數據的功能,所以我試圖在多個線程中運行它,但我得到了以下異常:的executeQuery在多線程關閉HSQLDB數據庫連接
java.sql.SQLNonTransientConnectionException: connection exception: closed
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatementBase.checkClosed(Unknown Source)
at org.hsqldb.jdbc.JDBCStatementBase.getResultSet(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.getResultSet(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.executeQuery(Unknown Source)
這是函數我試圖每次都在一個新的線程運行它:
public List<String> getAllClassNames(boolean concrete) throws ClassMapException {
List<String> result = new ArrayList<String>();
try {
ResultSet rs = null;
Connection connection = DBConnection.getConnection();
Statement st = connection.createStatement();
if (concrete)
rs = st.executeQuery("select cd_name from CLASS_DESCRIPTORS where CD_CONCRETE=true order by cd_name");
else
rs = st.executeQuery("select cd_name from CLASS_DESCRIPTORS order by cd_name");
while (rs.next()) {
result.add(rs.getString("cd_name"));
}
} catch (SQLException e) {
_log.error("SQLException while retrieve all class names." + e.getMessage(), e);
throw new ClassMapException("SQLException while retrieve all class names." + e.getMessage(), e);
} finally {
DBConnection.closeConnection();
}
return result;
}
我讀到執行多個選擇由不同的線程關閉連接。這是真的嗎?如何解決?
我該如何使用ARRAY_AGG?你能修改我的查詢來使用它嗎? – 2012-08-15 12:19:10
更新了答案。 – fredt 2012-08-15 15:41:44
我試過你的解決方案,但是當我執行rs.getArray(1)時,我得到了「無效遊標狀態:標識符遊標未定位在UPDATE,DELETE,SET或GET語句中的行上;; ResultSet定位在第一行之前」異常。你有什麼想法如何解決它? – 2012-08-16 09:14:10