Oracle DB を使用して Websphere コマース サイトを実行しており、DB 接続が不足しているという問題に直面しています。準備されたステートメントを取得し、接続を確立するために JDBCHelper シングルトンを使用しています。
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);
}
}