Discussions

Web tier: servlets, JSP, Web frameworks: sharing connection pool in JSPs

  1. sharing connection pool in JSPs (3 messages)

    Is there anybody who has done sharing a connection pool in Apache Server? I want to maitain a database connection pool so that many JSPs can use it. Thanks in advance.
  2. you can implement ur own connection pool as a bean and use it in the JSPs. For details about creating the Database connection pooling, refer the site "http://www.javaworld.com/javaworld/jw-06-1998/jw-06-object-pool.html".
  3. sharing connection pool in JSPs[ Go to top ]

    What you can do is have something like a DBContextInitializer..

    Basically, have this class load up a DBPool like
    DbConnectionBroker (http://www.javaexchange.com)
    during startup..

    What DBContextInitializer should do is insert the DBPOOL unto the servlet context tagged as some attribute name during startup (WEB-INF/web.xml).. Then any jsp can then grab that DBPOOL and use it..

    Ie.. jsps or servlets can then do this

    ServletContext thisContext = getServletContext();
    DbConnectionBroker dbPool = thisContext.getAttribute("dbPoolResource");
    Connection connDb = dbPool.getConnection();
    try {
    ...
    } catch ( SQLException sqlE){
    ...
    } finally {
        try {
           if ( connDb != null )
                 dbPool.freeConnection(connDb);
        } catch ( SQLException sqlE ){ ; }
    }
     
    Hope that makes sense.
  4. sharing connection pool in JSPs[ Go to top ]

    Thanks a lot, this is clear for me now.