Hi all,

I have a doubt in which method is the proper way of getting connections. I
am putting the connections in the server context, and getting  the
connections from the context by

ServletContext context = getServletContext();
OracleConnectionPool ocpl =
(OracleConnectionPool)context.getAttribute("CONNECTION_POOL");
OracleConnection tmpDbCon = (OracleConnection)ocpl.getConnection();

First Method:
I usually get the connection by the above method by putting it in the doPost
method of the servlet.

like public void doPost(HttpServletRequest req, HttpServletResponse res){
        ServletContext context = getServletContext();
        OracleConnectionPool ocpl =
(OracleConnectionPool)context.getAttribute("CONNECTION_POOL");
        OracleConnection tmpDbCon = (OracleConnection)ocpl.getConnection();
}

My colleague says that this method has its overheads since each and
everytime you fetch and release a connection. Which should be avoided.

So she tried the second method

Second Method:

Instead of fetching the connection from doPost method, she put it in the
init() method of the servlet like this

public void init()
{
        ServletContext context = getServletContext();
        OracleConnectionPool ocpl =
(OracleConnectionPool)context.getAttribute("CONNECTION_POOL");
        OracleConnection tmpDbCon = (OracleConnection)ocpl.getConnection();

}

Now the servlet will always have a connection. This connection shall be
released only when the destroy() method of the servlet is called. She says
this is better, since you dont everytime have to get and release the
connection. You have assigned one connection to it. If many users access
this servlet, then the service method shall handle it.

Could some java gurus throw some light on this.

Regards,
Vikramjit Singh,
Systems Engineer,
GTL Ltd.
Ph. 7612929-1031

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to