我們正在運行一個帶有oracle數據庫的websphere商業網站,並面臨着我們用完數據庫連接的問題。 我們使用JDBCHelper單例獲取準備好的語句並找出連接。無法關閉JDBC資源!
public static JDBCHelper getJDBCHelper() {
if (theObject == null){
theObject = new JDBCHelper();
}
return theObject;
}
public void closeResources(Connection con, PreparedStatement pstmt, ResultSet rs){
try{
if(rs!=null){ rs.close();}
}catch(SQLException e){
logger.info("Exception closing the resultset");
}try{
if(pstmt!=null) { pstmt.close(); }
}catch(SQLException e){
logger.info("Exception closing the preparedstatement");
}try{
if(con!=null){ con.close(); }
}catch(SQLException e){
logger.info("Exception closing the connection");
}
}
然而,當我們試圖讓使用prepStmt.getConnection()傳遞到接近資源執行後的連接,它拋出一個SQL例外。任何想法爲什麼?執行後立即關閉連接嗎?我們使用單例JDBCHelper有什麼不對嗎?
編輯
部分,這使得準備好的語句,執行和關閉連接
PreparedStatement pstmt = jdbcHelper.getPreparedStatement(query);
try{
//rest of the code
int brs = pstmt.executeUpdate();
}
finally{
try {
jdbcHelper.closeResources(pstmt.getConnection(),pstmt);
} catch (SQLException e1) {
logger.logp(Level.SEVERE,CLASS_NAME,methodName,"In the finally block - Could not close connection", e1);
}
}
代碼
謝謝...已經更新了一部分代碼...雖然看起來很直截了當 – sarego 2009-09-25 09:09:17