Alternatively, investigate connection pooling. There is quite a lot of reference to that if you do a Google search.
-----Original Message----- From: A mailing list about Java Server Pages specification and reference [mailto:[EMAIL PROTECTED]] On Behalf Of Padhu Vinirs Sent: 16 October 2002 13:50 To: [EMAIL PROTECTED] Subject: Re: Connection to database from jsp. Override jspInit() in a declaration block, create the connection, and save it as an attribute in ServletContext. -- padhu Anoop Kumar V wrote: >We have a system consisting of a group of jsps - which have links to one >another. There is no controller servlet as it is a simple system. What i >want is to access the database from the jsps. The problem is that I do not >want a new connection to be established everytime a request is made. What is >the solution for this? >I had initially thought of having a utility class and in that I can have a >getConnection method which returns the connection to a static connection >reference in the same utility class. This can then be assigned to the jsps >(by making a call from the jsps to some method - returnConn, in the utilily >class). Is it true that a new connection will be established everytime. This >has confused me a bit. >I am infact confused now about the very concept of static references. How do >you think this problem can be solved? Will a servlet be of any use? Actually >in a servlet, if we have a static connection reference as a class variable, >and the initialization is done ( acquiring a connection) in the init method >( as init is executed only once in the lifetime of a servlet), the problem >may be solved. In a servlet, the init method is executed only once and the >servlet does not go out of memory till the server comes down. So I presume >the connection will also be the same. Is this correct? Even if it is, I want >to avoid the servlet, as it will be a lot of rework if the servlet has to be >fit in. The application would have to be changed. Suggestions invited. > > >Anoop Kumar V. > >======================================================================= ==== >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 > > > ======================================================================== === 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 =========================================================================== 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