wood burning stoves 2.0*
The moose likes Struts and the fly likes where to close DBconnection in struts..urgent..please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "where to close DBconnection in struts..urgent..please help" Watch "where to close DBconnection in struts..urgent..please help" New topic

where to close DBconnection in struts..urgent..please help

Sri chirat

Joined: Aug 19, 2004
Posts: 3
I have DAO.java, DAOManager.java for database transactions in my application.
I am using STRuts1.1, eclipse,j2sdk1.4.2, MySql, Tomcat 5.0
where do I close the database connection ..
Is it in DAO class...inside the methods for the transactions.
1.if I do this...I am getting exception saying connection is closed in daomanager.
2.if I do this in DAOmanager class....not in DAO.java..then my application
hangs up after 3 or 4 transactions......

public void addProgramEnroll(Familyclient familyclient) throws DatastoreException{
PreparedStatement pspprogramenrollinfo = null;
try {
if (conn.isClosed()) {
throw new IllegalStateException("error.unexpected");
pspprogramenrollinfo = conn.prepareStatement(SQL_INSERT_PROGRAM);
} catch (SQLException ex) {
} catch (NumberFormatException nfe) {
} finally {
try {
if (pspprogramenrollinfo != null) {
} catch (SQLException e) {
throw new RuntimeException("error.unexpected");


public void addProgramEnroll(ServletContext sc, Familyclient familyclient)
throws DatastoreException {
Connection conn = getConnection(sc);
FamilyclientDao dao = new FamilyclientDao(conn);
}catch (Exception ex){
throw DatastoreException.datastoreError(ex);
}finally {
if (conn != null) {
try {
} catch (SQLException sqle) {
log.error("Exception closing connection", sqle);
I agree. Here's the link: http://aspose.com/file-tools
subject: where to close DBconnection in struts..urgent..please help
Similar Threads
java.sql.SQLException[ODBC Driver Manager]Data source name not found and no default driver specified
Exception handling in finally block
Dealing with multi-threading in servlets
finally block is not executing
Struts Web Application keeps hanging after 4 transacations with database