우리는 오라클 DB가있는 웹 스피어 (websphere) 상거래 사이트를 운영 중이고 DB 연결이 부족한 문제에 직면 해 있습니다. 준비된 명령문을 가져오고 연결을 처리하기 위해 JDBCHelper 싱글 톤을 사용하고 있습니다. 우리가 실행 한 후 가까운 자원 전달을위한 prepStmt.getConnection를 사용하여 연결을() 점점하려고 할 때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");
}
}
그러나 그것은 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